sequence
stringlengths 1.19k
35k
| code
stringlengths 75
8.58k
|
---|---|
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_find_cert_in_list'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cert'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'issuer'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'certificate_list'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'crl_issuer'}; {'id': '8', 'type': 'block', 'children': ['9', '17', '23', '29', '40', '46', '123']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'revoked_certificates'}; {'id': '12', 'type': 'subscript', 'children': ['13', '16']}, {'id': '13', 'type': 'subscript', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'certificate_list'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'tbs_cert_list'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'revoked_certificates'"}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'cert_serial'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cert'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'serial_number'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'issuer_name'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'issuer'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'subject'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'known_extensions'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'list', 'children': ['36', '37', '38', '39'], 'value': "[\n 'crl_reason',\n 'hold_instruction_code',\n 'invalidity_date',\n 'certificate_issuer'\n ]"}; {'id': '36', 'type': 'string', 'children': [], 'value': "'crl_reason'"}, {'id': '37', 'type': 'string', 'children': [], 'value': "'hold_instruction_code'"}; {'id': '38', 'type': 'string', 'children': [], 'value': "'invalidity_date'"}, {'id': '39', 'type': 'string', 'children': [], 'value': "'certificate_issuer'"}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'last_issuer_name'}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'crl_issuer'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'subject'}; {'id': '46', 'type': 'for_statement', 'children': ['47', '48', '49']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'revoked_cert'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'revoked_certificates'}, {'id': '49', 'type': 'block', 'children': ['50', '61', '78', '84', '94', '117']}; {'id': '50', 'type': 'if_statement', 'children': ['51', '56']}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '55'], 'value': '-'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'revoked_cert'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'critical_extensions'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'known_extensions'}; {'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': 'NotImplementedError'}; {'id': '60', 'type': 'argument_list', 'children': []}, {'id': '61', 'type': 'if_statement', 'children': ['62', '71']}; {'id': '62', 'type': 'boolean_operator', 'children': ['63', '66'], 'value': 'and'}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'revoked_cert'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'issuer_name'}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '70'], 'value': '!='}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'revoked_cert'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'issuer_name'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'last_issuer_name'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'last_issuer_name'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'revoked_cert'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'issuer_name'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '82']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': '!='}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'last_issuer_name'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'issuer_name'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'continue_statement', 'children': []}; {'id': '84', 'type': 'if_statement', 'children': ['85', '92']}, {'id': '85', 'type': 'comparison_operator', 'children': ['86', '91'], 'value': '!='}; {'id': '86', 'type': 'attribute', 'children': ['87', '90']}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'revoked_cert'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'user_certificate'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'native'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'cert_serial'}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'continue_statement', 'children': []}; {'id': '94', 'type': 'if_statement', 'children': ['95', '99', '109']}, {'id': '95', 'type': 'not_operator', 'children': ['96']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'revoked_cert'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'crl_reason_value'}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'crl_reason'}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'crl'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'CRLReason'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'unspecified'"}, {'id': '109', 'type': 'else_clause', 'children': ['110']}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'crl_reason'}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'revoked_cert'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'crl_reason_value'}, {'id': '117', 'type': 'return_statement', 'children': ['118']}; {'id': '118', 'type': 'tuple', 'children': ['119', '122']}, {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'revoked_cert'}, {'id': '121', 'type': 'string', 'children': [], 'value': "'revocation_date'"}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'crl_reason'}, {'id': '123', 'type': 'return_statement', 'children': ['124']}; {'id': '124', 'type': 'tuple', 'children': ['125', '126']}, {'id': '125', 'type': 'None', 'children': []} | def _find_cert_in_list(cert, issuer, certificate_list, crl_issuer):
revoked_certificates = certificate_list['tbs_cert_list']['revoked_certificates']
cert_serial = cert.serial_number
issuer_name = issuer.subject
known_extensions = set([
'crl_reason',
'hold_instruction_code',
'invalidity_date',
'certificate_issuer'
])
last_issuer_name = crl_issuer.subject
for revoked_cert in revoked_certificates:
if revoked_cert.critical_extensions - known_extensions:
raise NotImplementedError()
if revoked_cert.issuer_name and revoked_cert.issuer_name != last_issuer_name:
last_issuer_name = revoked_cert.issuer_name
if last_issuer_name != issuer_name:
continue
if revoked_cert['user_certificate'].native != cert_serial:
continue
if not revoked_cert.crl_reason_value:
crl_reason = crl.CRLReason('unspecified')
else:
crl_reason = revoked_cert.crl_reason_value
return (revoked_cert['revocation_date'], crl_reason)
return (None, None) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'derive_coordinates'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '12', '68', '72', '76', '80', '108', '289']}; {'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': '_coordinates_resolved'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': []}; {'id': '12', 'type': 'if_statement', 'children': ['13', '18', '60']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '17'], 'value': 'is'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'seg_map'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19', '39']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '29']}, {'id': '21', 'type': 'pattern_list', 'children': ['22', '25', '28']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'include_ref'}, {'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': 'seg_map'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'derive_source_offset'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '47']}, {'id': '41', 'type': 'pattern_list', 'children': ['42', '45', '46']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'end_filename'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '47', 'type': 'call', 'children': ['48', '53']}; {'id': '48', 'type': 'attribute', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'seg_map'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'derive_source_offset'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'is_end'}, {'id': '59', 'type': 'True', 'children': []}; {'id': '60', 'type': 'else_clause', 'children': ['61']}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'end_filename'}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'line_start'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'lineno'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'file_pos'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '86', '91', '102']}, {'id': '81', 'type': 'comparison_operator', 'children': ['82', '85'], 'value': '!='}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'end_filename'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'get_end'}; {'id': '90', 'type': 'False', 'children': []}, {'id': '91', 'type': 'elif_clause', 'children': ['92', '97']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '96'], 'value': 'is'}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '96', 'type': 'None', 'children': []}, {'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': 'get_end'}, {'id': '101', 'type': 'False', 'children': []}; {'id': '102', 'type': 'else_clause', 'children': ['103']}, {'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': 'get_end'}, {'id': '107', 'type': 'True', 'children': []}; {'id': '108', 'type': 'if_statement', 'children': ['109', '122']}, {'id': '109', 'type': 'boolean_operator', 'children': ['110', '116'], 'value': 'and'}; {'id': '110', 'type': 'parenthesized_expression', 'children': ['111'], 'value': '()'}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': 'is'}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '115', 'type': 'None', 'children': []}; {'id': '116', 'type': 'parenthesized_expression', 'children': ['117'], 'value': '()'}, {'id': '117', 'type': 'comparison_operator', 'children': ['118', '121'], 'value': 'is'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '121', 'type': 'None', 'children': []}; {'id': '122', 'type': 'block', 'children': ['123', '261']}, {'id': '123', 'type': 'with_statement', 'children': ['124', '142']}; {'id': '124', 'type': 'with_clause', 'children': ['125']}, {'id': '125', 'type': 'with_item', 'children': ['126']}; {'id': '126', 'type': 'as_pattern', 'children': ['127', '140']}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '133', '134', '137']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '133', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'newline'}; {'id': '136', 'type': 'string', 'children': [], 'value': "''"}, {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '139', 'type': 'string', 'children': [], 'value': "'utf_8'"}; {'id': '140', 'type': 'as_pattern_target', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'while_statement', 'children': ['144', '145']}; {'id': '144', 'type': 'True', 'children': []}, {'id': '145', 'type': 'block', 'children': ['146', '154', '161', '167', '219', '253', '257']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'line_text'}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'fp'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'readline'}, {'id': '153', 'type': 'argument_list', 'children': []}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'augmented_assignment', 'children': ['156', '157'], 'value': '+='}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'file_pos'}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'line_text'}, {'id': '161', 'type': 'if_statement', 'children': ['162', '165']}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': '=='}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'line_text'}; {'id': '164', 'type': 'string', 'children': [], 'value': '""'}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'break_statement', 'children': []}, {'id': '167', 'type': 'if_statement', 'children': ['168', '181']}; {'id': '168', 'type': 'boolean_operator', 'children': ['169', '175'], 'value': 'and'}, {'id': '169', 'type': 'parenthesized_expression', 'children': ['170'], 'value': '()'}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': 'is'}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'start_line'}; {'id': '174', 'type': 'None', 'children': []}, {'id': '175', 'type': 'parenthesized_expression', 'children': ['176'], 'value': '()'}; {'id': '176', 'type': 'comparison_operator', 'children': ['177', '180'], 'value': '<'}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'file_pos'}, {'id': '181', 'type': 'block', 'children': ['182', '188', '198', '214']}; {'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': 'start_line'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'lineno'}; {'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': 'self'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'start_col'}, {'id': '193', 'type': 'binary_operator', 'children': ['194', '197'], 'value': '-'}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'line_start'}; {'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': 'start_line_text'}, {'id': '203', 'type': 'call', 'children': ['204', '212']}; {'id': '204', 'type': 'attribute', 'children': ['205', '211']}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'line_text'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'rstrip'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'string', 'children': [], 'value': '"\\n"'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'rstrip'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'string', 'children': [], 'value': '"\\r"'}; {'id': '214', 'type': 'if_statement', 'children': ['215', '217']}, {'id': '215', 'type': 'not_operator', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'get_end'}, {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'break_statement', 'children': []}, {'id': '219', 'type': 'if_statement', 'children': ['220', '235']}; {'id': '220', 'type': 'boolean_operator', 'children': ['221', '229'], 'value': 'and'}, {'id': '221', 'type': 'boolean_operator', 'children': ['222', '223'], 'value': 'and'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'get_end'}, {'id': '223', 'type': 'parenthesized_expression', 'children': ['224'], 'value': '()'}; {'id': '224', 'type': 'comparison_operator', 'children': ['225', '228'], 'value': 'is'}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'end_line'}; {'id': '228', 'type': 'None', 'children': []}, {'id': '229', 'type': 'parenthesized_expression', 'children': ['230'], 'value': '()'}; {'id': '230', 'type': 'comparison_operator', 'children': ['231', '234'], 'value': '<'}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'file_pos'}, {'id': '235', 'type': 'block', 'children': ['236', '242', '252']}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'end_line'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'lineno'}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'end_col'}, {'id': '247', 'type': 'binary_operator', 'children': ['248', '251'], 'value': '-'}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'line_start'}; {'id': '252', 'type': 'break_statement', 'children': []}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'augmented_assignment', 'children': ['255', '256'], 'value': '+='}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'lineno'}; {'id': '256', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'assignment', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'line_start'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'file_pos'}, {'id': '261', 'type': 'if_statement', 'children': ['262', '264']}; {'id': '262', 'type': 'not_operator', 'children': ['263']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'get_end'}; {'id': '264', 'type': 'block', 'children': ['265', '273', '281']}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '270']}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'end_line'}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'start_line'}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '278']}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'end_col'}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'start_col'}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '286']}, {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': '_coordinates_resolved'} | def derive_coordinates(self):
if self._coordinates_resolved:
return
if self.seg_map is not None:
self.start, self.filename, include_ref = self.seg_map.derive_source_offset(self.start)
self.end, end_filename, _ = self.seg_map.derive_source_offset(self.end, is_end=True)
else:
end_filename = self.filename
line_start = 0
lineno = 1
file_pos = 0
if self.filename != end_filename:
get_end = False
elif self.end is None:
get_end = False
else:
get_end = True
if (self.filename is not None) and (self.start is not None):
with open(self.filename, 'r', newline='', encoding='utf_8') as fp:
while True:
line_text = fp.readline()
file_pos += len(line_text)
if line_text == "":
break
if (self.start_line is None) and (self.start < file_pos):
self.start_line = lineno
self.start_col = self.start - line_start
self.start_line_text = line_text.rstrip("\n").rstrip("\r")
if not get_end:
break
if get_end and (self.end_line is None) and (self.end < file_pos):
self.end_line = lineno
self.end_col = self.end - line_start
break
lineno += 1
line_start = file_pos
if not get_end:
self.end_line = self.start_line
self.end_col = self.start_col
self.end = self.start
self._coordinates_resolved = True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'children'}, {'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': 'unroll'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'skip_not_present'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'for_statement', 'children': ['13', '14', '19']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'child_inst'}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'inst'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '19', 'type': 'block', 'children': ['20', '36']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'skip_not_present'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'if_statement', 'children': ['24', '34']}; {'id': '24', 'type': 'not_operator', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '31']}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'child_inst'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'ispresent'"}, {'id': '33', 'type': 'True', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'continue_statement', 'children': []}; {'id': '36', 'type': 'if_statement', 'children': ['37', '50', '96']}, {'id': '37', 'type': 'boolean_operator', 'children': ['38', '47'], 'value': 'and'}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '40'], 'value': 'and'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'unroll'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'child_inst'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'AddressableComponent'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'child_inst'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'is_array'}; {'id': '50', 'type': 'block', 'children': ['51', '64']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'range_list'}; {'id': '54', 'type': 'list_comprehension', 'children': ['55', '59']}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '59', 'type': 'for_in_clause', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'child_inst'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'array_dimensions'}; {'id': '64', 'type': 'for_statement', 'children': ['65', '66', '73']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'idxs'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'itertools'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'product'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'list_splat', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'range_list'}, {'id': '73', 'type': 'block', 'children': ['74', '87', '93']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'Node'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': '_factory'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '83', '86']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'child_inst'}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'N'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'current_idx'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'idxs'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'yield', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '96', 'type': 'else_clause', 'children': ['97']}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'yield', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'Node'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': '_factory'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '106', '109']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'child_inst'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'env'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'} | def children(self, unroll=False, skip_not_present=True):
for child_inst in self.inst.children:
if skip_not_present:
if not child_inst.properties.get('ispresent', True):
continue
if unroll and isinstance(child_inst, comp.AddressableComponent) and child_inst.is_array:
range_list = [range(n) for n in child_inst.array_dimensions]
for idxs in itertools.product(*range_list):
N = Node._factory(child_inst, self.env, self)
N.current_idx = idxs
yield N
else:
yield Node._factory(child_inst, self.env, self) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_by_path'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '20', '173']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'pathparts'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'current_node'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'pathpart'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'pathparts'}, {'id': '23', 'type': 'block', 'children': ['24', '34', '43', '55', '73', '82', '89']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'fullmatch'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "r'^(\\w+)((?:\\[(?:\\d+|0[xX][\\da-fA-F]+)\\])*)$'"}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pathpart'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '37']}, {'id': '35', 'type': 'not_operator', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'raise_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': '"Invalid path"'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '48']}, {'id': '45', 'type': 'pattern_list', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'inst_name'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'array_suffix'}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'idx_list'}; {'id': '58', 'type': 'list_comprehension', 'children': ['59', '64']}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '63', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'findall'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}, {'id': '71', 'type': 'string', 'children': [], 'value': "r'\\[(\\d+|0[xX][\\da-fA-F]+)\\]'"}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'array_suffix'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'current_node'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'get_child_by_name'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'inst_name'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '86']}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'is'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'current_node'}, {'id': '85', 'type': 'None', 'children': []}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'return_statement', 'children': ['88']}; {'id': '88', 'type': 'None', 'children': []}, {'id': '89', 'type': 'if_statement', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'idx_list'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'if_statement', 'children': ['93', '105', '166']}, {'id': '93', 'type': 'boolean_operator', 'children': ['94', '100'], 'value': 'and'}; {'id': '94', 'type': 'parenthesized_expression', 'children': ['95'], 'value': '()'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'current_node'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'AddressableNode'}; {'id': '100', 'type': 'attribute', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'current_node'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'inst'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'is_array'}, {'id': '105', 'type': 'block', 'children': ['106', '126', '132']}; {'id': '106', 'type': 'if_statement', 'children': ['107', '120']}, {'id': '107', 'type': 'comparison_operator', 'children': ['108', '112'], 'value': '!='}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'idx_list'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'attribute', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'inst'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'array_dimensions'}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'raise_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'string', 'children': [], 'value': '"Wrong number of array dimensions"'}; {'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': 'current_node'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'current_idx'}, {'id': '131', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '132', 'type': 'for_statement', 'children': ['133', '136', '140']}, {'id': '133', 'type': 'pattern_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'idx_list'}; {'id': '140', 'type': 'block', 'children': ['141', '157']}, {'id': '141', 'type': 'if_statement', 'children': ['142', '151']}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '>='}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '144', 'type': 'subscript', 'children': ['145', '150']}, {'id': '145', 'type': 'attribute', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'inst'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'array_dimensions'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'raise_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'IndexError'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'string', 'children': [], 'value': '"Array index out of range"'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '164']}, {'id': '159', 'type': 'attribute', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'current_node'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'current_idx'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '166', 'type': 'else_clause', 'children': ['167']}, {'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': 'IndexError'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'string', 'children': [], 'value': '"Index attempted on non-array component"'}, {'id': '173', 'type': 'return_statement', 'children': ['174']} | def find_by_path(self, path):
pathparts = path.split('.')
current_node = self
for pathpart in pathparts:
m = re.fullmatch(r'^(\w+)((?:\[(?:\d+|0[xX][\da-fA-F]+)\])*)$', pathpart)
if not m:
raise ValueError("Invalid path")
inst_name, array_suffix = m.group(1,2)
idx_list = [ int(s,0) for s in re.findall(r'\[(\d+|0[xX][\da-fA-F]+)\]', array_suffix) ]
current_node = current_node.get_child_by_name(inst_name)
if current_node is None:
return None
if idx_list:
if (isinstance(current_node, AddressableNode)) and current_node.inst.is_array:
if len(idx_list) != len(current_node.inst.array_dimensions):
raise IndexError("Wrong number of array dimensions")
current_node.current_idx = []
for i,idx in enumerate(idx_list):
if idx >= current_node.inst.array_dimensions[i]:
raise IndexError("Array index out of range")
current_node.current_idx.append(idx)
else:
raise IndexError("Index attempted on non-array component")
return current_node |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_property'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'prop_name'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '17', '35', '54', '112', '117', '130', '142', '161']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'ovr_default'}; {'id': '12', 'type': 'False', 'children': []}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'in'}, {'id': '19', 'type': 'string', 'children': [], 'value': "'default'"}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '21', 'type': 'block', 'children': ['22', '26']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ovr_default'}, {'id': '25', 'type': 'True', 'children': []}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'default'"}, {'id': '35', 'type': 'if_statement', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'raise_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '44'], 'value': '%'}, {'id': '43', 'type': 'string', 'children': [], 'value': '"got an unexpected keyword argument \'%s\'"'}; {'id': '44', 'type': 'subscript', 'children': ['45', '53']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '52', 'type': 'argument_list', 'children': []}, {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '62']}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'in'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'prop_name'}, {'id': '57', 'type': 'attribute', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'inst'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '62', 'type': 'block', 'children': ['63', '73', '94', '110']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'prop_value'}; {'id': '66', 'type': 'subscript', 'children': ['67', '72']}, {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'inst'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'prop_name'}, {'id': '73', 'type': 'if_statement', 'children': ['74', '81']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'prop_value'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'rdltypes'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ComponentRef'}, {'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': 'prop_value'}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'prop_value'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'build_node_ref'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '94', 'type': 'if_statement', 'children': ['95', '102']}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'rdltypes'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'PropertyReference'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'prop_value'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': '_resolve_node'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'return_statement', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'prop_value'}; {'id': '112', 'type': 'if_statement', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'ovr_default'}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'return_statement', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '120', 'type': 'call', 'children': ['121', '128']}, {'id': '121', 'type': 'attribute', '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': 'env'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'property_rules'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'lookup_property'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'prop_name'}; {'id': '130', 'type': 'if_statement', 'children': ['131', '134']}, {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'is'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'rule'}, {'id': '133', 'type': 'None', 'children': []}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'raise_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'LookupError'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '%'}; {'id': '140', 'type': 'string', 'children': [], 'value': '"Unknown property \'%s\'"'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'prop_name'}; {'id': '142', 'type': 'if_statement', 'children': ['143', '153']}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '150'], 'value': 'not'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'inst'}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'bindable_to'}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'raise_statement', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'LookupError'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '%'}, {'id': '159', 'type': 'string', 'children': [], 'value': '"Unknown property \'%s\'"'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'prop_name'}, {'id': '161', 'type': 'return_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'rule'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'get_default'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'} | def get_property(self, prop_name, **kwargs):
ovr_default = False
default = None
if 'default' in kwargs:
ovr_default = True
default = kwargs.pop('default')
if kwargs:
raise TypeError("got an unexpected keyword argument '%s'" % list(kwargs.keys())[0])
if prop_name in self.inst.properties:
prop_value = self.inst.properties[prop_name]
if isinstance(prop_value, rdltypes.ComponentRef):
prop_value = prop_value.build_node_ref(self, self.env)
if isinstance(prop_value, rdltypes.PropertyReference):
prop_value._resolve_node(self)
return prop_value
if ovr_default:
return default
rule = self.env.property_rules.lookup_property(prop_name)
if rule is None:
raise LookupError("Unknown property '%s'" % prop_name)
if type(self.inst) not in rule.bindable_to:
raise LookupError("Unknown property '%s'" % prop_name)
return rule.get_default(self) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'elaborate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'top_def_name'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'inst_name'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '24', '131', '140', '146', '154', '160', '167', '173', '179', '185', '191', '210', '303', '312', '323', '343', '375', '395', '411']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '19']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'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': 'parameters'}, {'id': '23', 'type': 'dictionary', 'children': []}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28', '80']}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'top_def_name'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29', '49', '59']}, {'id': '29', 'type': 'if_statement', 'children': ['30', '37']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'not'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'top_def_name'}; {'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': 'root'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'comp_defs'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'fatal'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '%'}, {'id': '47', 'type': 'string', 'children': [], 'value': '"Elaboration target \'%s\' not found"'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'top_def_name'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'top_def'}; {'id': '52', 'type': 'subscript', 'children': ['53', '58']}, {'id': '53', 'type': 'attribute', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'comp_defs'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'top_def_name'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '68']}; {'id': '60', 'type': 'not_operator', 'children': ['61']}, {'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': 'top_def'}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'comp'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'Addrmap'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '76']}, {'id': '71', 'type': 'attribute', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'fatal'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '%'}; {'id': '78', 'type': 'string', 'children': [], 'value': '"Elaboration target \'%s\' is not an \'addrmap\' component"'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'top_def_name'}; {'id': '80', 'type': 'else_clause', 'children': ['81']}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'for_statement', 'children': ['83', '84', '99', '120']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'comp_def'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'reversed'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '98']}, {'id': '91', 'type': 'attribute', 'children': ['92', '97']}; {'id': '92', 'type': 'attribute', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'comp_defs'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '98', 'type': 'argument_list', 'children': []}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'if_statement', 'children': ['101', '108']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'comp_def'}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'comp'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'Addrmap'}; {'id': '108', 'type': 'block', 'children': ['109', '113', '119']}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'top_def'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'comp_def'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'top_def_name'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'comp_def'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'type_name'}, {'id': '119', 'type': 'break_statement', 'children': []}; {'id': '120', 'type': 'else_clause', 'children': ['121']}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '129']}; {'id': '124', 'type': 'attribute', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'fatal'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'string', 'children': [], 'value': '"Could not find any \'addrmap\' components to elaborate"'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'root_inst'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'root_inst'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'is_instance'}, {'id': '145', 'type': 'True', 'children': []}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'root_inst'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'original_def'}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'root_inst'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'inst_name'}, {'id': '159', 'type': 'string', 'children': [], 'value': '"$root"'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'top_inst'}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'top_def'}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'top_inst'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'is_instance'}; {'id': '172', 'type': 'True', 'children': []}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'top_inst'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'original_def'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'top_def'}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'top_inst'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'addr_offset'}; {'id': '184', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'top_inst'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'external'}; {'id': '190', 'type': 'True', 'children': []}, {'id': '191', 'type': 'if_statement', 'children': ['192', '195', '202']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'is'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'inst_name'}; {'id': '194', 'type': 'None', 'children': []}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'top_inst'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'inst_name'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'inst_name'}; {'id': '202', 'type': 'else_clause', 'children': ['203']}, {'id': '203', 'type': 'block', 'children': ['204']}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'assignment', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'top_inst'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'inst_name'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'top_def_name'}; {'id': '210', 'type': 'for_statement', 'children': ['211', '214', '219']}, {'id': '211', 'type': 'pattern_list', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'param_name'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '218', 'type': 'argument_list', 'children': []}, {'id': '219', 'type': 'block', 'children': ['220', '224', '251', '263', '271', '283', '297']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'parameter'}, {'id': '223', 'type': 'None', 'children': []}; {'id': '224', 'type': 'for_statement', 'children': ['225', '226', '229', '242']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'top_inst'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '229', 'type': 'block', 'children': ['230']}; {'id': '230', 'type': 'if_statement', 'children': ['231', '236']}, {'id': '231', 'type': 'comparison_operator', 'children': ['232', '235'], 'value': '=='}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'param_name'}; {'id': '236', 'type': 'block', 'children': ['237', '241']}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '241', 'type': 'break_statement', 'children': []}; {'id': '242', 'type': 'else_clause', 'children': ['243']}, {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'raise_statement', 'children': ['245']}, {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '%'}, {'id': '249', 'type': 'string', 'children': [], 'value': '"Parameter \'%s\' is not available for override"'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'param_name'}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'value_expr'}; {'id': '254', 'type': 'call', 'children': ['255', '258']}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'expr'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'ExternalLiteral'}; {'id': '258', 'type': 'argument_list', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'value_type'}; {'id': '266', 'type': 'call', 'children': ['267', '270']}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'value_expr'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'predict_type'}; {'id': '270', 'type': 'argument_list', 'children': []}, {'id': '271', 'type': 'if_statement', 'children': ['272', '275']}; {'id': '272', 'type': 'comparison_operator', 'children': ['273', '274'], 'value': 'is'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'value_type'}; {'id': '274', 'type': 'None', 'children': []}, {'id': '275', 'type': 'block', 'children': ['276']}; {'id': '276', 'type': 'raise_statement', 'children': ['277']}, {'id': '277', 'type': 'call', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'binary_operator', 'children': ['281', '282'], 'value': '%'}, {'id': '281', 'type': 'string', 'children': [], 'value': '"Override value for parameter \'%s\' is an unrecognized type"'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'param_name'}, {'id': '283', 'type': 'if_statement', 'children': ['284', '289']}; {'id': '284', 'type': 'comparison_operator', 'children': ['285', '286'], 'value': '!='}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'value_type'}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'parameter'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'param_type'}, {'id': '289', 'type': 'block', 'children': ['290']}; {'id': '290', 'type': 'raise_statement', 'children': ['291']}, {'id': '291', 'type': 'call', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'binary_operator', 'children': ['295', '296'], 'value': '%'}, {'id': '295', 'type': 'string', 'children': [], 'value': '"Incorrect type for parameter \'%s\'"'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'param_name'}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '302']}, {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'parameter'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'expr'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'value_expr'}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'call', 'children': ['305', '310']}, {'id': '305', 'type': 'attribute', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'root_inst'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'top_inst'}; {'id': '312', 'type': 'expression_statement', 'children': ['313']}, {'id': '313', 'type': 'assignment', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'root_node'}, {'id': '315', 'type': 'call', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'RootNode'}, {'id': '317', 'type': 'argument_list', 'children': ['318', '319', '322']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'root_inst'}, {'id': '319', 'type': 'attribute', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '322', 'type': 'None', 'children': []}, {'id': '323', 'type': 'expression_statement', 'children': ['324']}; {'id': '324', 'type': 'call', 'children': ['325', '335']}, {'id': '325', 'type': 'attribute', 'children': ['326', '334']}; {'id': '326', 'type': 'call', 'children': ['327', '330']}, {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'walker'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'RDLWalker'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}, {'id': '331', 'type': 'keyword_argument', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'skip_not_present'}, {'id': '333', 'type': 'False', 'children': []}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'walk'}, {'id': '335', 'type': 'argument_list', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'root_node'}, {'id': '337', 'type': 'call', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'ElabExpressionsListener'}, {'id': '339', 'type': 'argument_list', 'children': ['340']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '343', 'type': 'expression_statement', 'children': ['344']}; {'id': '344', 'type': 'call', 'children': ['345', '355']}, {'id': '345', 'type': 'attribute', 'children': ['346', '354']}; {'id': '346', 'type': 'call', 'children': ['347', '350']}, {'id': '347', 'type': 'attribute', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'walker'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'RDLWalker'}; {'id': '350', 'type': 'argument_list', 'children': ['351']}, {'id': '351', 'type': 'keyword_argument', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'skip_not_present'}, {'id': '353', 'type': 'False', 'children': []}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'walk'}, {'id': '355', 'type': 'argument_list', 'children': ['356', '357', '363', '369']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'root_node'}, {'id': '357', 'type': 'call', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'PrePlacementValidateListener'}, {'id': '359', 'type': 'argument_list', 'children': ['360']}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '363', 'type': 'call', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'StructuralPlacementListener'}, {'id': '365', 'type': 'argument_list', 'children': ['366']}; {'id': '366', 'type': 'attribute', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '369', 'type': 'call', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'LateElabListener'}, {'id': '371', 'type': 'argument_list', 'children': ['372']}; {'id': '372', 'type': 'attribute', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '375', 'type': 'expression_statement', 'children': ['376']}; {'id': '376', 'type': 'call', 'children': ['377', '387']}, {'id': '377', 'type': 'attribute', 'children': ['378', '386']}; {'id': '378', 'type': 'call', 'children': ['379', '382']}, {'id': '379', 'type': 'attribute', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'walker'}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'RDLWalker'}; {'id': '382', 'type': 'argument_list', 'children': ['383']}, {'id': '383', 'type': 'keyword_argument', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'skip_not_present'}, {'id': '385', 'type': 'True', 'children': []}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'walk'}, {'id': '387', 'type': 'argument_list', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'root_node'}, {'id': '389', 'type': 'call', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'ValidateListener'}, {'id': '391', 'type': 'argument_list', 'children': ['392']}; {'id': '392', 'type': 'attribute', 'children': ['393', '394']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'env'}, {'id': '395', 'type': 'if_statement', 'children': ['396', '401']}; {'id': '396', 'type': 'attribute', 'children': ['397', '400']}, {'id': '397', 'type': 'attribute', 'children': ['398', '399']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'had_error'}, {'id': '401', 'type': 'block', 'children': ['402']}; {'id': '402', 'type': 'expression_statement', 'children': ['403']}, {'id': '403', 'type': 'call', 'children': ['404', '409']}; {'id': '404', 'type': 'attribute', 'children': ['405', '408']}, {'id': '405', 'type': 'attribute', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'fatal'}, {'id': '409', 'type': 'argument_list', 'children': ['410']}; {'id': '410', 'type': 'string', 'children': [], 'value': '"Elaborate aborted due to previous errors"'}, {'id': '411', 'type': 'return_statement', 'children': ['412']} | def elaborate(self, top_def_name=None, inst_name=None, parameters=None):
if parameters is None:
parameters = {}
if top_def_name is not None:
if top_def_name not in self.root.comp_defs:
self.msg.fatal("Elaboration target '%s' not found" % top_def_name)
top_def = self.root.comp_defs[top_def_name]
if not isinstance(top_def, comp.Addrmap):
self.msg.fatal("Elaboration target '%s' is not an 'addrmap' component" % top_def_name)
else:
for comp_def in reversed(list(self.root.comp_defs.values())):
if isinstance(comp_def, comp.Addrmap):
top_def = comp_def
top_def_name = comp_def.type_name
break
else:
self.msg.fatal("Could not find any 'addrmap' components to elaborate")
root_inst = deepcopy(self.root)
root_inst.is_instance = True
root_inst.original_def = self.root
root_inst.inst_name = "$root"
top_inst = deepcopy(top_def)
top_inst.is_instance = True
top_inst.original_def = top_def
top_inst.addr_offset = 0
top_inst.external = True
if inst_name is not None:
top_inst.inst_name = inst_name
else:
top_inst.inst_name = top_def_name
for param_name, value in parameters.items():
parameter = None
for p in top_inst.parameters:
if p.name == param_name:
parameter = p
break
else:
raise ValueError("Parameter '%s' is not available for override" % param_name)
value_expr = expr.ExternalLiteral(self.env, value)
value_type = value_expr.predict_type()
if value_type is None:
raise TypeError("Override value for parameter '%s' is an unrecognized type" % param_name)
if value_type != parameter.param_type:
raise TypeError("Incorrect type for parameter '%s'" % param_name)
parameter.expr = value_expr
root_inst.children.append(top_inst)
root_node = RootNode(root_inst, self.env, None)
walker.RDLWalker(skip_not_present=False).walk(
root_node,
ElabExpressionsListener(self.msg)
)
walker.RDLWalker(skip_not_present=False).walk(
root_node,
PrePlacementValidateListener(self.msg),
StructuralPlacementListener(self.msg),
LateElabListener(self.msg)
)
walker.RDLWalker(skip_not_present=True).walk(root_node, ValidateListener(self.env))
if self.msg.had_error:
self.msg.fatal("Elaborate aborted due to previous errors")
return root_node |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'resolve_addresses'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '25', '29', '258', '282']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'prop_alignment'}; {'id': '10', 'type': 'subscript', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'alignment_stack'}; {'id': '14', 'type': 'unary_operator', 'children': ['15'], 'value': '-'}, {'id': '15', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'prop_alignment'}, {'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': 'prop_alignment'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'prev_node'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'for_statement', 'children': ['30', '31', '39']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'child_node'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'keyword_argument', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'skip_not_present'}; {'id': '38', 'type': 'False', 'children': []}, {'id': '39', 'type': 'block', 'children': ['40', '49', '63', '97', '105', '114', '210', '219', '242', '254']}; {'id': '40', 'type': 'if_statement', 'children': ['41', '47']}, {'id': '41', 'type': 'not_operator', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'child_node'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'AddressableNode'}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'continue_statement', 'children': []}, {'id': '49', 'type': 'if_statement', 'children': ['50', '57']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '56'], 'value': 'is'}, {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'child_node'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'inst'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'addr_offset'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'block', 'children': ['58', '62']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'prev_node'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'child_node'}; {'id': '62', 'type': 'continue_statement', 'children': []}, {'id': '63', 'type': 'if_statement', 'children': ['64', '69']}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'chk_implicit_addr'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '79']}; {'id': '72', 'type': 'attribute', 'children': ['73', '78']}, {'id': '73', 'type': 'attribute', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'env'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '85', '92']}; {'id': '80', 'type': 'attribute', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'chk_implicit_addr'}, {'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '%'}; {'id': '86', 'type': 'string', 'children': [], 'value': '"Address offset of component \'%s\' is not explicitly set"'}, {'id': '87', 'type': 'attribute', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'child_node'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'inst'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'inst_name'}; {'id': '92', 'type': 'attribute', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'child_node'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'inst'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'inst_src_ref'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'alloc_alignment'}; {'id': '100', 'type': 'attribute', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'child_node'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'inst'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'addr_align'}, {'id': '105', 'type': 'if_statement', 'children': ['106', '109']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': 'is'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'alloc_alignment'}; {'id': '108', 'type': 'None', 'children': []}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'alloc_alignment'}, {'id': '113', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '127', '152', '179', '206']}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '122'], 'value': '=='}; {'id': '116', 'type': 'subscript', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'addressing_mode_stack'}; {'id': '120', 'type': 'unary_operator', 'children': ['121'], 'value': '-'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'attribute', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'rdltypes'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'AddressingType'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'compact'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'if_statement', 'children': ['129', '134', '146']}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'child_node'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'RegNode'}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'mode_alignment'}; {'id': '138', 'type': 'binary_operator', 'children': ['139', '145'], 'value': '//'}, {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'child_node'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'get_property'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'string', 'children': [], 'value': "'accesswidth'"}, {'id': '145', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '146', 'type': 'else_clause', 'children': ['147']}, {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'mode_alignment'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '152', 'type': 'elif_clause', 'children': ['153', '165']}, {'id': '153', 'type': 'comparison_operator', 'children': ['154', '160'], 'value': '=='}; {'id': '154', 'type': 'subscript', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'addressing_mode_stack'}; {'id': '158', 'type': 'unary_operator', 'children': ['159'], 'value': '-'}, {'id': '159', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '160', 'type': 'attribute', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'rdltypes'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'AddressingType'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'regalign'}, {'id': '165', 'type': 'block', 'children': ['166', '172']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'mode_alignment'}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'child_node'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'mode_alignment'}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'roundup_pow2'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'mode_alignment'}, {'id': '179', 'type': 'elif_clause', 'children': ['180', '192']}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '187'], 'value': '=='}, {'id': '181', 'type': 'subscript', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'addressing_mode_stack'}, {'id': '185', 'type': 'unary_operator', 'children': ['186'], 'value': '-'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '187', 'type': 'attribute', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'rdltypes'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'AddressingType'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'fullalign'}; {'id': '192', 'type': 'block', 'children': ['193', '199']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'mode_alignment'}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'child_node'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'total_size'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'mode_alignment'}; {'id': '202', 'type': 'call', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'roundup_pow2'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'mode_alignment'}; {'id': '206', 'type': 'else_clause', 'children': ['207']}, {'id': '207', 'type': 'block', 'children': ['208']}; {'id': '208', 'type': 'raise_statement', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'alignment'}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '215', 'type': 'argument_list', 'children': ['216', '217', '218']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'prop_alignment'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'alloc_alignment'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'mode_alignment'}, {'id': '219', 'type': 'if_statement', 'children': ['220', '223', '228']}; {'id': '220', 'type': 'comparison_operator', 'children': ['221', '222'], 'value': 'is'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'prev_node'}; {'id': '222', 'type': 'None', 'children': []}, {'id': '223', 'type': 'block', 'children': ['224']}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'next_offset'}, {'id': '227', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '228', 'type': 'else_clause', 'children': ['229']}, {'id': '229', 'type': 'block', 'children': ['230']}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'next_offset'}, {'id': '233', 'type': 'binary_operator', 'children': ['234', '239'], 'value': '+'}; {'id': '234', 'type': 'attribute', 'children': ['235', '238']}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'prev_node'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'inst'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'addr_offset'}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'prev_node'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'total_size'}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '249']}; {'id': '244', 'type': 'attribute', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'child_node'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'inst'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'addr_offset'}, {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'roundup_to'}, {'id': '251', 'type': 'argument_list', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'next_offset'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'alignment'}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'assignment', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'prev_node'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'child_node'}; {'id': '258', 'type': 'function_definition', 'children': ['259', '260', '262']}, {'id': '259', 'type': 'function_name', 'children': [], 'value': 'get_child_sort_key'}; {'id': '260', 'type': 'parameters', 'children': ['261']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'inst'}; {'id': '262', 'type': 'block', 'children': ['263']}, {'id': '263', 'type': 'if_statement', 'children': ['264', '272', '276']}; {'id': '264', 'type': 'not_operator', 'children': ['265']}, {'id': '265', 'type': 'call', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '267', 'type': 'argument_list', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'inst'}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'comp'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'AddressableComponent'}; {'id': '272', 'type': 'block', 'children': ['273']}, {'id': '273', 'type': 'return_statement', 'children': ['274']}; {'id': '274', 'type': 'unary_operator', 'children': ['275'], 'value': '-'}, {'id': '275', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '276', 'type': 'else_clause', 'children': ['277']}, {'id': '277', 'type': 'block', 'children': ['278']}; {'id': '278', 'type': 'return_statement', 'children': ['279']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'inst'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'addr_offset'}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}, {'id': '283', 'type': 'call', 'children': ['284', '291']}; {'id': '284', 'type': 'attribute', 'children': ['285', '290']}, {'id': '285', 'type': 'attribute', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'inst'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'keyword_argument', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'key'} | def resolve_addresses(self, node):
prop_alignment = self.alignment_stack[-1]
if prop_alignment is None:
prop_alignment = 1
prev_node = None
for child_node in node.children(skip_not_present=False):
if not isinstance(child_node, AddressableNode):
continue
if child_node.inst.addr_offset is not None:
prev_node = child_node
continue
if node.env.chk_implicit_addr:
node.env.msg.message(
node.env.chk_implicit_addr,
"Address offset of component '%s' is not explicitly set" % child_node.inst.inst_name,
child_node.inst.inst_src_ref
)
alloc_alignment = child_node.inst.addr_align
if alloc_alignment is None:
alloc_alignment = 1
if self.addressing_mode_stack[-1] == rdltypes.AddressingType.compact:
if isinstance(child_node, RegNode):
mode_alignment = child_node.get_property('accesswidth') // 8
else:
mode_alignment = 1
elif self.addressing_mode_stack[-1] == rdltypes.AddressingType.regalign:
mode_alignment = child_node.size
mode_alignment = roundup_pow2(mode_alignment)
elif self.addressing_mode_stack[-1] == rdltypes.AddressingType.fullalign:
mode_alignment = child_node.total_size
mode_alignment = roundup_pow2(mode_alignment)
else:
raise RuntimeError
alignment = max(prop_alignment, alloc_alignment, mode_alignment)
if prev_node is None:
next_offset = 0
else:
next_offset = prev_node.inst.addr_offset + prev_node.total_size
child_node.inst.addr_offset = roundup_to(next_offset, alignment)
prev_node = child_node
def get_child_sort_key(inst):
if not isinstance(inst, comp.AddressableComponent):
return -1
else:
return inst.addr_offset
node.inst.children.sort(key=get_child_sort_key) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_include'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '32', '36', '88', '97', '109', '139', '155', '166', '175', '184', '253', '321', '357', '363', '410']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '11', 'type': 'while_statement', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '13', 'type': 'block', 'children': ['14', '28']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '22']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '21'], 'value': '=='}; {'id': '16', 'type': 'subscript', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '22', 'type': 'block', 'children': ['23', '27']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'augmented_assignment', 'children': ['25', '26'], 'value': '+='}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '26', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '27', 'type': 'break_statement', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'augmented_assignment', 'children': ['30', '31'], 'value': '-='}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '31', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'line_start'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '62']}, {'id': '37', 'type': 'not_operator', 'children': ['38']}; {'id': '38', 'type': 'parenthesized_expression', 'children': ['39'], 'value': '()'}, {'id': '39', 'type': 'boolean_operator', 'children': ['40', '50'], 'value': 'or'}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '49'], 'value': '=='}, {'id': '41', 'type': 'subscript', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '45', 'type': 'slice', 'children': ['46', '47', '48']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'line_start'}, {'id': '47', 'type': 'colon', 'children': []}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '49', 'type': 'string', 'children': [], 'value': '""'}; {'id': '50', 'type': 'call', 'children': ['51', '61']}, {'id': '51', 'type': 'attribute', 'children': ['52', '60']}; {'id': '52', 'type': 'subscript', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '56', 'type': 'slice', 'children': ['57', '58', '59']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'line_start'}; {'id': '58', 'type': 'colon', 'children': []}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'isspace'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '72']}, {'id': '65', 'type': 'attribute', 'children': ['66', '71']}; {'id': '66', 'type': 'attribute', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'fatal'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'string', 'children': [], 'value': '"Unexpected text before include"'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'SourceRef'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80', '83']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'line_start'}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '-'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'inc_regex'}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'compile'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'string', 'children': [], 'value': 'r\'`include\\s+("([^\\r\\n]+)"|<([^\\r\\n]+)>)\''}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'm_inc'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'inc_regex'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '109', 'type': 'if_statement', 'children': ['110', '113']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'm_inc'}; {'id': '112', 'type': 'None', 'children': []}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '123']}; {'id': '116', 'type': 'attribute', 'children': ['117', '122']}, {'id': '117', 'type': 'attribute', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'env'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'fatal'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': '"Invalid usage of include directive"'}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'messages'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'SourceRef'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131', '134']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '+'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '7'}; {'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'incl_path_raw'}; {'id': '142', 'type': 'boolean_operator', 'children': ['143', '149'], 'value': 'or'}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'm_inc'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'm_inc'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '158', 'type': 'binary_operator', 'children': ['159', '165'], 'value': '-'}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'm_inc'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'path_start'}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'm_inc'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'tail_regex'}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'compile'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'string', 'children': [], 'value': "r'(?:[ \\t]*/\\*[^\\r\\n]*?\\*/)*[ \\t]*(?://[^\\r\\n]*?|/\\*[^\\r\\n]*?)?\\r?\\n'"}; {'id': '184', 'type': 'if_statement', 'children': ['185', '197']}, {'id': '185', 'type': 'not_operator', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'tail_regex'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '+'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '197', 'type': 'block', 'children': ['198', '207', '221']}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'tail_capture_regex'}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'compile'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'string', 'children': [], 'value': "r'[^\\r\\n]*?\\r?\\n'"}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '210', 'type': 'call', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'tail_capture_regex'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '+'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '220', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'call', 'children': ['223', '230']}, {'id': '223', 'type': 'attribute', 'children': ['224', '229']}; {'id': '224', 'type': 'attribute', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'fatal'}; {'id': '230', 'type': 'argument_list', 'children': ['231', '232']}, {'id': '231', 'type': 'string', 'children': [], 'value': '"Unexpected text after include"'}; {'id': '232', 'type': 'call', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'SourceRef'}; {'id': '236', 'type': 'argument_list', 'children': ['237', '240', '248']}, {'id': '237', 'type': 'binary_operator', 'children': ['238', '239'], 'value': '+'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '239', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '240', 'type': 'binary_operator', 'children': ['241', '247'], 'value': '-'}, {'id': '241', 'type': 'call', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '247', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '253', 'type': 'if_statement', 'children': ['254', '262', '267']}; {'id': '254', 'type': 'call', 'children': ['255', '260']}, {'id': '255', 'type': 'attribute', 'children': ['256', '259']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'isabs'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'incl_path_raw'}; {'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': 'incl_path'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'incl_path_raw'}, {'id': '267', 'type': 'else_clause', 'children': ['268']}; {'id': '268', 'type': 'block', 'children': ['269']}, {'id': '269', 'type': 'for_statement', 'children': ['270', '271', '274', '298']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'search_path'}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'search_paths'}; {'id': '274', 'type': 'block', 'children': ['275', '287']}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'incl_path'}; {'id': '278', 'type': 'call', 'children': ['279', '284']}, {'id': '279', 'type': 'attribute', 'children': ['280', '283']}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'search_path'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'incl_path_raw'}, {'id': '287', 'type': 'if_statement', 'children': ['288', '296']}; {'id': '288', 'type': 'call', 'children': ['289', '294']}, {'id': '289', 'type': 'attribute', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'incl_path'}; {'id': '296', 'type': 'block', 'children': ['297']}, {'id': '297', 'type': 'break_statement', 'children': []}; {'id': '298', 'type': 'else_clause', 'children': ['299']}, {'id': '299', 'type': 'block', 'children': ['300']}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'incl_path'}, {'id': '303', 'type': 'call', 'children': ['304', '309']}; {'id': '304', 'type': 'attribute', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '309', 'type': 'argument_list', 'children': ['310', '320']}; {'id': '310', 'type': 'call', 'children': ['311', '316']}, {'id': '311', 'type': 'attribute', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'incl_path_raw'}, {'id': '321', 'type': 'if_statement', 'children': ['322', '331']}; {'id': '322', 'type': 'not_operator', 'children': ['323']}, {'id': '323', 'type': 'call', 'children': ['324', '329']}; {'id': '324', 'type': 'attribute', 'children': ['325', '328']}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'isfile'}, {'id': '329', 'type': 'argument_list', 'children': ['330']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'incl_path'}, {'id': '331', 'type': 'block', 'children': ['332']}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}, {'id': '333', 'type': 'call', 'children': ['334', '341']}; {'id': '334', 'type': 'attribute', 'children': ['335', '340']}, {'id': '335', 'type': 'attribute', 'children': ['336', '339']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'env'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'fatal'}, {'id': '341', 'type': 'argument_list', 'children': ['342', '345']}; {'id': '342', 'type': 'binary_operator', 'children': ['343', '344'], 'value': '%'}, {'id': '343', 'type': 'string', 'children': [], 'value': '"Could not find \'%s\' in include search paths"'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'incl_path_raw'}, {'id': '345', 'type': 'call', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'messages'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'SourceRef'}, {'id': '349', 'type': 'argument_list', 'children': ['350', '351', '352']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'path_start'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '352', 'type': 'keyword_argument', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '354', 'type': 'attribute', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '357', 'type': 'expression_statement', 'children': ['358']}; {'id': '358', 'type': 'assignment', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'incl_ref'}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'incl_ref'}, {'id': '363', 'type': 'while_statement', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'incl_ref'}, {'id': '365', 'type': 'block', 'children': ['366', '404']}; {'id': '366', 'type': 'if_statement', 'children': ['367', '378']}, {'id': '367', 'type': 'call', 'children': ['368', '373']}; {'id': '368', 'type': 'attribute', 'children': ['369', '372']}, {'id': '369', 'type': 'attribute', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'samefile'}, {'id': '373', 'type': 'argument_list', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'incl_path'}, {'id': '375', 'type': 'attribute', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'incl_ref'}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '378', 'type': 'block', 'children': ['379']}, {'id': '379', 'type': 'expression_statement', 'children': ['380']}; {'id': '380', 'type': 'call', 'children': ['381', '388']}, {'id': '381', 'type': 'attribute', 'children': ['382', '387']}; {'id': '382', 'type': 'attribute', 'children': ['383', '386']}, {'id': '383', 'type': 'attribute', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'fatal'}; {'id': '388', 'type': 'argument_list', 'children': ['389', '392']}, {'id': '389', 'type': 'binary_operator', 'children': ['390', '391'], 'value': '%'}; {'id': '390', 'type': 'string', 'children': [], 'value': '"Include of \'%s\' results in a circular reference"'}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'incl_path_raw'}; {'id': '392', 'type': 'call', 'children': ['393', '396']}, {'id': '393', 'type': 'attribute', 'children': ['394', '395']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'messages'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'SourceRef'}; {'id': '396', 'type': 'argument_list', 'children': ['397', '398', '399']}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'path_start'}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '399', 'type': 'keyword_argument', 'children': ['400', '401']}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '401', 'type': 'attribute', 'children': ['402', '403']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '404', 'type': 'expression_statement', 'children': ['405']}, {'id': '405', 'type': 'assignment', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'incl_ref'}, {'id': '407', 'type': 'attribute', 'children': ['408', '409']}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'incl_ref'}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '410', 'type': 'return_statement', 'children': ['411']}, {'id': '411', 'type': 'tuple', 'children': ['412', '413']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'incl_path'} | def parse_include(self, start):
i = start
while i:
if self.text[i] == '\n':
i += 1
break
i -= 1
line_start = i
if not (self.text[line_start:start] == "" or self.text[line_start:start].isspace()):
self.env.msg.fatal(
"Unexpected text before include",
messages.SourceRef(line_start, start-1, filename=self.path)
)
inc_regex = re.compile(r'`include\s+("([^\r\n]+)"|<([^\r\n]+)>)')
m_inc = inc_regex.match(self.text, start)
if m_inc is None:
self.env.msg.fatal(
"Invalid usage of include directive",
messages.SourceRef(start, start+7, filename=self.path)
)
incl_path_raw = m_inc.group(2) or m_inc.group(3)
end = m_inc.end(0)-1
path_start = m_inc.start(1)
tail_regex = re.compile(r'(?:[ \t]*/\*[^\r\n]*?\*/)*[ \t]*(?://[^\r\n]*?|/\*[^\r\n]*?)?\r?\n')
if not tail_regex.match(self.text, end+1):
tail_capture_regex = re.compile(r'[^\r\n]*?\r?\n')
m = tail_capture_regex.match(self.text, end+1)
self.env.msg.fatal(
"Unexpected text after include",
messages.SourceRef(end+1, m.end(0)-1, filename=self.path)
)
if os.path.isabs(incl_path_raw):
incl_path = incl_path_raw
else:
for search_path in self.search_paths:
incl_path = os.path.join(search_path, incl_path_raw)
if os.path.isfile(incl_path):
break
else:
incl_path = os.path.join(os.path.dirname(self.path), incl_path_raw)
if not os.path.isfile(incl_path):
self.env.msg.fatal(
"Could not find '%s' in include search paths" % incl_path_raw,
messages.SourceRef(path_start, end, filename=self.path)
)
incl_ref = self.incl_ref
while incl_ref:
if os.path.samefile(incl_path, incl_ref.path):
self.env.msg.fatal(
"Include of '%s' results in a circular reference" % incl_path_raw,
messages.SourceRef(path_start, end, filename=self.path)
)
incl_ref = incl_ref.parent
return(end, incl_path) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_paths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'patterns'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'start_dirs'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'max_depth'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '11', 'type': 'block', 'children': ['12', '63', '79']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '22']}, {'id': '13', 'type': 'boolean_operator', 'children': ['14', '20'], 'value': 'and'}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '19'], 'value': '=='}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'patterns'}, {'id': '19', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '20', 'type': 'not_operator', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'start_dirs'}; {'id': '22', 'type': 'block', 'children': ['23', '29', '40']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'patterns'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'directory'}; {'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': 'dirname'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'directory'}; {'id': '42', 'type': 'block', 'children': ['43', '55', '59']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'patterns'}; {'id': '46', 'type': 'list', 'children': ['47'], 'value': '[os.path.basename(pattern)]'}, {'id': '47', 'type': 'call', 'children': ['48', '53']}; {'id': '48', 'type': 'attribute', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'start_dirs'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'directory'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'max_depth'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '63', 'type': 'if_statement', 'children': ['64', '70']}; {'id': '64', 'type': 'boolean_operator', 'children': ['65', '67'], 'value': 'or'}, {'id': '65', 'type': 'not_operator', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'start_dirs'}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '=='}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'start_dirs'}, {'id': '69', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'start_dirs'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'getcwd'}; {'id': '78', 'type': 'argument_list', 'children': []}, {'id': '79', 'type': 'for_statement', 'children': ['80', '81', '87']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'start_dir'}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'start_dirs'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'string', 'children': [], 'value': "','"}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'for_statement', 'children': ['89', '93', '99']}, {'id': '89', 'type': 'pattern_list', 'children': ['90', '91', '92']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'dirs'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'walk'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'start_dir'}, {'id': '99', 'type': 'block', 'children': ['100', '139', '143', '157']}; {'id': '100', 'type': 'if_statement', 'children': ['101', '104']}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'is'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'max_depth'}, {'id': '103', 'type': 'None', 'children': []}; {'id': '104', 'type': 'block', 'children': ['105', '119', '133']}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'relpath'}; {'id': '108', 'type': 'call', 'children': ['109', '114']}, {'id': '109', 'type': 'attribute', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'relpath'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'start_dir'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'relpath'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'sep'}, {'id': '133', 'type': 'if_statement', 'children': ['134', '137']}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': '>'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'depth'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'max_depth'}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'continue_statement', 'children': []}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '142', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '143', 'type': 'for_statement', 'children': ['144', '145', '146']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'patterns'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'augmented_assignment', 'children': ['149', '150'], 'value': '+='}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '150', 'type': 'call', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'fnmatch'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '157', 'type': 'for_statement', 'children': ['158', '159', '160']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '160', 'type': 'block', 'children': ['161', '173']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '164', 'type': 'call', 'children': ['165', '170']}, {'id': '165', 'type': 'attribute', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'yield', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'path'} | def get_paths(patterns, start_dirs=None, max_depth=1):
if len(patterns) == 1 and not start_dirs:
pattern = patterns[0]
directory = os.path.dirname(pattern)
if directory:
patterns = [os.path.basename(pattern)]
start_dirs = directory
max_depth = 1
if not start_dirs or start_dirs == '.':
start_dirs = os.getcwd()
for start_dir in start_dirs.split(','):
for root, dirs, files in os.walk(start_dir):
if max_depth is not None:
relpath = os.path.relpath(root, start=start_dir)
depth = len(relpath.split(os.sep))
if depth > max_depth:
continue
names = []
for pattern in patterns:
names += fnmatch.filter(files, pattern)
for name in names:
path = os.path.join(root, name)
yield path |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '34']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'edit_files'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '28', '31']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'patterns'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'expressions'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'functions'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'executables'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'start_dirs'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'max_depth'}, {'id': '19', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dry_run'}; {'id': '22', 'type': 'True', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'default_parameter', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'newline'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35', '47', '61', '75', '89', '104', '114', '124', '134', '138', '255']}, {'id': '35', 'type': 'if_statement', 'children': ['36', '41']}; {'id': '36', 'type': 'not_operator', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'is_list'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'patterns'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'raise_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'string', 'children': [], 'value': '"patterns should be a list"'}, {'id': '47', 'type': 'if_statement', 'children': ['48', '55']}; {'id': '48', 'type': 'boolean_operator', 'children': ['49', '50'], 'value': 'and'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'expressions'}; {'id': '50', 'type': 'not_operator', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'is_list'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'expressions'}, {'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': 'TypeError'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'string', 'children': [], 'value': '"expressions should be a list of exec expressions"'}, {'id': '61', 'type': 'if_statement', 'children': ['62', '69']}; {'id': '62', 'type': 'boolean_operator', 'children': ['63', '64'], 'value': 'and'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'functions'}; {'id': '64', 'type': 'not_operator', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'is_list'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'functions'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'raise_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': '"functions should be a list of functions"'}, {'id': '75', 'type': 'if_statement', 'children': ['76', '83']}; {'id': '76', 'type': 'boolean_operator', 'children': ['77', '78'], 'value': 'and'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'executables'}; {'id': '78', 'type': 'not_operator', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'is_list'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'executables'}, {'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': 'TypeError'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'string', 'children': [], 'value': '"executables should be a list of program names"'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'editor'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'MassEdit'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '98', '101']}, {'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'dry_run'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'dry_run'}; {'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'newline'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'newline'}; {'id': '104', 'type': 'if_statement', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'expressions'}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'editor'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'set_code_exprs'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'expressions'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'functions'}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'editor'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'set_functions'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'functions'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'executables'}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'editor'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'set_executables'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'executables'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'processed_paths'}, {'id': '137', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '138', 'type': 'for_statement', 'children': ['139', '140', '150']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'get_paths'}; {'id': '142', 'type': 'argument_list', 'children': ['143', '144', '147']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'patterns'}; {'id': '144', 'type': 'keyword_argument', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'start_dirs'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'start_dirs'}, {'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'max_depth'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'max_depth'}; {'id': '150', 'type': 'block', 'children': ['151', '241']}, {'id': '151', 'type': 'try_statement', 'children': ['152', '225']}; {'id': '152', 'type': 'block', 'children': ['153', '165']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'diffs'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'editor'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'edit_file'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '165', 'type': 'if_statement', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'dry_run'}, {'id': '167', 'type': 'block', 'children': ['168', '177', '182', '188', '218']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'string', 'children': [], 'value': '""'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'diffs'}, {'id': '177', 'type': 'if_statement', 'children': ['178', '180']}; {'id': '178', 'type': 'not_operator', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '180', 'type': 'block', 'children': ['181']}, {'id': '181', 'type': 'continue_statement', 'children': []}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '188', 'type': 'if_statement', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '190', 'type': 'block', 'children': ['191', '205']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'bytes_diff'}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '202']}, {'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '204', 'type': 'string', 'children': [], 'value': "'ignore'"}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'bytes_diff'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'diff'}, {'id': '225', 'type': 'except_clause', 'children': ['226', '230']}; {'id': '226', 'type': 'as_pattern', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'}; {'id': '228', 'type': 'as_pattern_target', 'children': ['229']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '230', 'type': 'block', 'children': ['231', '240']}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '236', 'type': 'argument_list', 'children': ['237', '238', '239']}, {'id': '237', 'type': 'string', 'children': [], 'value': '"failed to process %s: %s"'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '240', 'type': 'continue_statement', 'children': []}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '246']}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'processed_paths'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'call', 'children': ['248', '253']}; {'id': '248', 'type': 'attribute', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'abspath'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '255', 'type': 'return_statement', 'children': ['256']} | def edit_files(patterns, expressions=None,
functions=None, executables=None,
start_dirs=None, max_depth=1, dry_run=True,
output=sys.stdout, encoding=None, newline=None):
if not is_list(patterns):
raise TypeError("patterns should be a list")
if expressions and not is_list(expressions):
raise TypeError("expressions should be a list of exec expressions")
if functions and not is_list(functions):
raise TypeError("functions should be a list of functions")
if executables and not is_list(executables):
raise TypeError("executables should be a list of program names")
editor = MassEdit(dry_run=dry_run, encoding=encoding, newline=newline)
if expressions:
editor.set_code_exprs(expressions)
if functions:
editor.set_functions(functions)
if executables:
editor.set_executables(executables)
processed_paths = []
for path in get_paths(patterns, start_dirs=start_dirs,
max_depth=max_depth):
try:
diffs = list(editor.edit_file(path))
if dry_run:
diff = "".join(diffs)
if not diff:
continue
encoding = output.encoding
if encoding:
bytes_diff = diff.encode(encoding=encoding, errors='ignore')
diff = bytes_diff.decode(encoding=output.encoding)
output.write(diff)
except UnicodeDecodeError as err:
log.error("failed to process %s: %s", path, err)
continue
processed_paths.append(os.path.abspath(path))
return processed_paths |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'detect_events'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dat'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '200', '243']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '18']}, {'id': '11', 'type': 'boolean_operator', 'children': ['12', '15'], 'value': 'or'}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'in'}, {'id': '13', 'type': 'string', 'children': [], 'value': "'thresh'"}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': '=='}; {'id': '16', 'type': 'string', 'children': [], 'value': "'custom'"}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '18', 'type': 'block', 'children': ['19', '37', '55', '91', '103', '110', '155']}, {'id': '19', 'type': 'if_statement', 'children': ['20', '23']}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': '=='}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'above_thresh'"}, {'id': '23', 'type': 'block', 'children': ['24', '30']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'above_det'}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': '>='}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dat'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'detected'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_detect_start_end'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'above_det'}, {'id': '37', 'type': 'if_statement', 'children': ['38', '41']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'below_thresh'"}, {'id': '41', 'type': 'block', 'children': ['42', '48']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'below_det'}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '<'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'dat'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'detected'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_detect_start_end'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'below_det'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '59']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '=='}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'between_thresh'"}, {'id': '59', 'type': 'block', 'children': ['60', '68', '76', '84']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'above_det'}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': '>='}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'dat'}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'below_det'}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': '<'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'dat'}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'between_det'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'logical_and'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'above_det'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'below_det'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'detected'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': '_detect_start_end'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'between_det'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '95']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': '=='}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'custom'"}, {'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': 'detected'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': '_detect_start_end'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'dat'}, {'id': '103', 'type': 'if_statement', 'children': ['104', '107']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': 'is'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'detected'}; {'id': '106', 'type': 'None', 'children': []}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'return_statement', 'children': ['109']}, {'id': '109', 'type': 'None', 'children': []}; {'id': '110', 'type': 'if_statement', 'children': ['111', '116']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'in'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '113', 'type': 'list', 'children': ['114', '115'], 'value': "['above_thresh', 'custom']"}; {'id': '114', 'type': 'string', 'children': [], 'value': "'above_thresh'"}, {'id': '115', 'type': 'string', 'children': [], 'value': "'custom'"}; {'id': '116', 'type': 'block', 'children': ['117', '129']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'detected'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '124', '125', '126']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'detected'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '125', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '128', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '129', 'type': 'for_statement', 'children': ['130', '131', '132']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'detected'}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '138']}, {'id': '135', 'type': 'subscript', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '138', 'type': 'binary_operator', 'children': ['139', '142'], 'value': '+'}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '141', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'argmax'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'dat'}, {'id': '147', 'type': 'slice', 'children': ['148', '151', '152']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '151', 'type': 'colon', 'children': []}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '155', 'type': 'if_statement', 'children': ['156', '161']}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'in'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '158', 'type': 'list', 'children': ['159', '160'], 'value': "['below_thresh', 'between_thresh']"}, {'id': '159', 'type': 'string', 'children': [], 'value': "'below_thresh'"}; {'id': '160', 'type': 'string', 'children': [], 'value': "'between_thresh'"}, {'id': '161', 'type': 'block', 'children': ['162', '174']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'detected'}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'insert'}, {'id': '167', 'type': 'argument_list', 'children': ['168', '169', '170', '171']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'detected'}, {'id': '169', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '170', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '171', 'type': 'keyword_argument', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '173', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '174', 'type': 'for_statement', 'children': ['175', '176', '177']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'detected'}, {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '183']}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '183', 'type': 'binary_operator', 'children': ['184', '187'], 'value': '+'}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'argmin'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'subscript', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'dat'}; {'id': '192', 'type': 'slice', 'children': ['193', '196', '197']}, {'id': '193', 'type': 'subscript', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '195', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '196', 'type': 'colon', 'children': []}, {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '199', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '200', 'type': 'if_statement', 'children': ['201', '204']}, {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': '=='}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '203', 'type': 'string', 'children': [], 'value': "'maxima'"}; {'id': '204', 'type': 'block', 'children': ['205', '214', '226']}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'assignment', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'peaks'}; {'id': '208', 'type': 'subscript', 'children': ['209', '213']}, {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'argrelmax'}, {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'dat'}, {'id': '213', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'detected'}, {'id': '217', 'type': 'attribute', 'children': ['218', '225']}; {'id': '218', 'type': 'call', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'vstack'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'tuple', 'children': ['222', '223', '224']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'peaks'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'peaks'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'peaks'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'T'}; {'id': '226', 'type': 'if_statement', 'children': ['227', '230']}, {'id': '227', 'type': 'comparison_operator', 'children': ['228', '229'], 'value': 'is'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '229', 'type': 'None', 'children': []}; {'id': '230', 'type': 'block', 'children': ['231']}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'assignment', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'detected'}; {'id': '234', 'type': 'subscript', 'children': ['235', '236', '241']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'detected'}; {'id': '236', 'type': 'comparison_operator', 'children': ['237', '240'], 'value': '>'}, {'id': '237', 'type': 'subscript', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'dat'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'peaks'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '241', 'type': 'slice', 'children': ['242']}; {'id': '242', 'type': 'colon', 'children': []}, {'id': '243', 'type': 'return_statement', 'children': ['244']} | def detect_events(dat, method, value=None):
if 'thresh' in method or 'custom' == method:
if method == 'above_thresh':
above_det = dat >= value
detected = _detect_start_end(above_det)
if method == 'below_thresh':
below_det = dat < value
detected = _detect_start_end(below_det)
if method == 'between_thresh':
above_det = dat >= value[0]
below_det = dat < value[1]
between_det = logical_and(above_det, below_det)
detected = _detect_start_end(between_det)
if method == 'custom':
detected = _detect_start_end(dat)
if detected is None:
return None
if method in ['above_thresh', 'custom']:
detected = insert(detected, 1, 0, axis=1)
for i in detected:
i[1] = i[0] + argmax(dat[i[0]:i[2]])
if method in ['below_thresh', 'between_thresh']:
detected = insert(detected, 1, 0, axis=1)
for i in detected:
i[1] = i[0] + argmin(dat[i[0]:i[2]])
if method == 'maxima':
peaks = argrelmax(dat)[0]
detected = vstack((peaks, peaks, peaks)).T
if value is not None:
detected = detected[dat[peaks] > value, :]
return detected |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_close'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'events'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'min_interval'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'merge_to_longer'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '16', '20', '142']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'half_iv'}, {'id': '13', 'type': 'binary_operator', 'children': ['14', '15'], 'value': '/'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'min_interval'}, {'id': '15', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'merged'}, {'id': '19', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'higher'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'events'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '27', '35']}, {'id': '25', 'type': 'not_operator', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'merged'}, {'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': 'merged'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'higher'}, {'id': '35', 'type': 'else_clause', 'children': ['36']}; {'id': '36', 'type': 'block', 'children': ['37', '44']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'merged'}; {'id': '42', 'type': 'unary_operator', 'children': ['43'], 'value': '-'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '56', '133']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '51'], 'value': '<='}; {'id': '46', 'type': 'binary_operator', 'children': ['47', '50'], 'value': '-'}, {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'higher'}, {'id': '49', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'half_iv'}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '55'], 'value': '+'}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'end'"}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'half_iv'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'if_statement', 'children': ['58', '76', '106']}; {'id': '58', 'type': 'boolean_operator', 'children': ['59', '60'], 'value': 'and'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'merge_to_longer'}; {'id': '60', 'type': 'parenthesized_expression', 'children': ['61'], 'value': '()'}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '69'], 'value': '>'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '66'], 'value': '-'}, {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'higher'}, {'id': '65', 'type': 'string', 'children': [], 'value': "'end'"}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'higher'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'start'"}, {'id': '69', 'type': 'binary_operator', 'children': ['70', '73'], 'value': '-'}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'end'"}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '75', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '76', 'type': 'block', 'children': ['77', '89', '99']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '86']}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '85', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'higher'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'start'"}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'higher'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'dictionary', 'children': ['96']}; {'id': '96', 'type': 'pair', 'children': ['97', '98']}, {'id': '97', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '105']}, {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'merged'}, {'id': '103', 'type': 'unary_operator', 'children': ['104'], 'value': '-'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'higher'}; {'id': '106', 'type': 'else_clause', 'children': ['107']}, {'id': '107', 'type': 'block', 'children': ['108', '120']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '117']}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'end'"}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'higher'}, {'id': '119', 'type': 'string', 'children': [], 'value': "'end'"}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '128']}; {'id': '122', 'type': 'attribute', 'children': ['123', '127']}, {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'merged'}, {'id': '125', 'type': 'unary_operator', 'children': ['126'], 'value': '-'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'dictionary', 'children': ['130']}; {'id': '130', 'type': 'pair', 'children': ['131', '132']}, {'id': '131', 'type': 'string', 'children': [], 'value': "'end'"}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '133', 'type': 'else_clause', 'children': ['134']}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'merged'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'higher'}; {'id': '142', 'type': 'return_statement', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'merged'} | def merge_close(events, min_interval, merge_to_longer=False):
half_iv = min_interval / 2
merged = []
for higher in events:
if not merged:
merged.append(higher)
else:
lower = merged[-1]
if higher['start'] - half_iv <= lower['end'] + half_iv:
if merge_to_longer and (higher['end'] - higher['start'] >
lower['end'] - lower['start']):
start = min(lower['start'], higher['start'])
higher.update({'start': start})
merged[-1] = higher
else:
end = max(lower['end'], higher['end'])
merged[-1].update({'end': end})
else:
merged.append(higher)
return merged |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_remove_duplicate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'old_events'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dat'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '42', '46', '59', '75', '98', '102', '106', '185']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'diff_events'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'old_events'}; {'id': '14', 'type': 'keyword_argument', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'dupl'}; {'id': '20', 'type': 'subscript', 'children': ['21', '41']}, {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'where'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '33'], 'value': '&'}, {'id': '25', 'type': 'parenthesized_expression', 'children': ['26'], 'value': '()'}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '32'], 'value': '=='}, {'id': '27', 'type': 'subscript', 'children': ['28', '29', '31']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'diff_events'}, {'id': '29', 'type': 'slice', 'children': ['30']}; {'id': '30', 'type': 'colon', 'children': []}, {'id': '31', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '33', 'type': 'parenthesized_expression', 'children': ['34'], 'value': '()'}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '40'], 'value': '=='}, {'id': '35', 'type': 'subscript', 'children': ['36', '37', '39']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'diff_events'}, {'id': '37', 'type': 'slice', 'children': ['38']}; {'id': '38', 'type': 'colon', 'children': []}, {'id': '39', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'augmented_assignment', 'children': ['44', '45'], 'value': '+='}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'dupl'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'n_nondupl_events'}, {'id': '49', 'type': 'binary_operator', 'children': ['50', '55'], 'value': '-'}; {'id': '50', 'type': 'subscript', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'old_events'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'dupl'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'new_events'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '72']}, {'id': '65', 'type': 'tuple', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'n_nondupl_events'}, {'id': '67', 'type': 'subscript', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'old_events'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'shape'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'int'"}, {'id': '75', 'type': 'if_statement', 'children': ['76', '80']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'dupl'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'lg'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'binary_operator', 'children': ['88', '97'], 'value': '+'}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '+'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'Removing '"}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'dupl'}, {'id': '97', 'type': 'string', 'children': [], 'value': "' duplicate events'"}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'indices'}, {'id': '105', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '106', 'type': 'for_statement', 'children': ['107', '110', '114']}, {'id': '107', 'type': 'pattern_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'i_old'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'one_old_event'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'old_events'}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'if_statement', 'children': ['116', '119', '139']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'not'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'i_old'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'dupl'}, {'id': '119', 'type': 'block', 'children': ['120', '128', '132']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '127']}; {'id': '122', 'type': 'subscript', 'children': ['123', '124', '125']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'new_events'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '125', 'type': 'slice', 'children': ['126']}; {'id': '126', 'type': 'colon', 'children': []}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'one_old_event'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'augmented_assignment', 'children': ['130', '131'], 'value': '+='}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '131', 'type': 'integer', 'children': [], 'value': '1'}; {'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': 'indices'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'i_old'}, {'id': '139', 'type': 'else_clause', 'children': ['140']}; {'id': '140', 'type': 'block', 'children': ['141', '150', '156']}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'peak_0'}; {'id': '144', 'type': 'subscript', 'children': ['145', '146', '149']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'new_events'}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '-'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'peak_1'}, {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'one_old_event'}, {'id': '155', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '156', 'type': 'if_statement', 'children': ['157', '164', '174']}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '161'], 'value': '>='}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'dat'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'peak_0'}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'dat'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'peak_1'}; {'id': '164', 'type': 'block', 'children': ['165']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '173']}, {'id': '167', 'type': 'subscript', 'children': ['168', '169', '172']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'new_events'}, {'id': '169', 'type': 'binary_operator', 'children': ['170', '171'], 'value': '-'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '171', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'peak_0'}; {'id': '174', 'type': 'else_clause', 'children': ['175']}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '184']}; {'id': '178', 'type': 'subscript', 'children': ['179', '180', '183']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'new_events'}; {'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '-'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '183', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'peak_1'}, {'id': '185', 'type': 'return_statement', 'children': ['186']}; {'id': '186', 'type': 'expression_list', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'indices'} | def _remove_duplicate(old_events, dat):
diff_events = diff(old_events, axis=0)
dupl = where((diff_events[:, 0] == 0) & (diff_events[:, 2] == 0))[0]
dupl += 1
n_nondupl_events = old_events.shape[0] - len(dupl)
new_events = zeros((n_nondupl_events, old_events.shape[1]), dtype='int')
if len(dupl):
lg.debug('Removing ' + str(len(dupl)) + ' duplicate events')
i = 0
indices = []
for i_old, one_old_event in enumerate(old_events):
if i_old not in dupl:
new_events[i, :] = one_old_event
i += 1
indices.append(i_old)
else:
peak_0 = new_events[i - 1, 1]
peak_1 = one_old_event[1]
if dat[peak_0] >= dat[peak_1]:
new_events[i - 1, 1] = peak_0
else:
new_events[i - 1, 1] = peak_1
return indices, new_events |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'math'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'operator_name'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '31', '73', '84', '88', '193', '201', '215', '219', '422']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '23']}; {'id': '16', 'type': 'boolean_operator', 'children': ['17', '20'], 'value': 'and'}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'operator_name'}; {'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': 'TypeError'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'concatenated_string', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': '\'Parameters "operator" and "operator_name" are \''}; {'id': '30', 'type': 'string', 'children': [], 'value': "'mutually exclusive'"}, {'id': '31', 'type': 'if_statement', 'children': ['32', '35']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'operator_name'}; {'id': '34', 'type': 'None', 'children': []}, {'id': '35', 'type': 'block', 'children': ['36', '48', '52', '66']}; {'id': '36', 'type': 'if_statement', 'children': ['37', '42']}, {'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': 'operator_name'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'operator_name'}; {'id': '46', 'type': 'tuple', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'operator_name'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'operators'}, {'id': '51', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'one_operator_name'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'operator_name'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'operators'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'eval'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'one_operator_name'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'operators'}, {'id': '73', 'type': 'if_statement', 'children': ['74', '78']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'operator'}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'operator'}; {'id': '82', 'type': 'tuple', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'operator'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'operations'}, {'id': '87', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '88', 'type': 'for_statement', 'children': ['89', '90', '91']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'one_operator'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'operator'}, {'id': '91', 'type': 'block', 'children': ['92', '96', '100', '172']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'on_axis'}, {'id': '95', 'type': 'False', 'children': []}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'keepdims'}, {'id': '99', 'type': 'True', 'children': []}; {'id': '100', 'type': 'try_statement', 'children': ['101', '111', '130']}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '105', 'type': 'attribute', 'children': ['106', '110']}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'getfullargspec'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'one_operator'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '111', 'type': 'except_clause', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'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': 'lg'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'binary_operator', 'children': ['121', '127'], 'value': '+'}, {'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '+'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'func '"}, {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'one_operator'}, {'id': '127', 'type': 'concatenated_string', 'children': ['128', '129']}; {'id': '128', 'type': 'string', 'children': [], 'value': "' is not a Python '"}, {'id': '129', 'type': 'string', 'children': [], 'value': "'function'"}; {'id': '130', 'type': 'else_clause', 'children': ['131']}, {'id': '131', 'type': 'block', 'children': ['132', '159']}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'in'}; {'id': '134', 'type': 'string', 'children': [], 'value': "'axis'"}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '136', 'type': 'block', 'children': ['137', '141']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'on_axis'}; {'id': '140', 'type': 'True', 'children': []}, {'id': '141', 'type': 'if_statement', 'children': ['142', '145']}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'is'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '144', 'type': 'None', 'children': []}, {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'raise_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'binary_operator', 'children': ['151', '158'], 'value': '+'}, {'id': '151', 'type': 'binary_operator', 'children': ['152', '155'], 'value': '+'}; {'id': '152', 'type': 'concatenated_string', 'children': ['153', '154']}, {'id': '153', 'type': 'string', 'children': [], 'value': "'You need to specify an axis if you '"}; {'id': '154', 'type': 'string', 'children': [], 'value': "'use '"}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'one_operator'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '158', 'type': 'string', 'children': [], 'value': "' (which applies to an axis)'"}, {'id': '159', 'type': 'if_statement', 'children': ['160', '167']}; {'id': '160', 'type': 'boolean_operator', 'children': ['161', '164'], 'value': 'or'}, {'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': 'in'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'keepdims'"}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': 'in'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'one_operator'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'NOKEEPDIM'}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'keepdims'}, {'id': '171', 'type': 'False', 'children': []}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'operations'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'dictionary', 'children': ['179', '184', '187', '190']}, {'id': '179', 'type': 'pair', 'children': ['180', '181']}; {'id': '180', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'one_operator'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '184', 'type': 'pair', 'children': ['185', '186']}, {'id': '185', 'type': 'string', 'children': [], 'value': "'func'"}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'one_operator'}, {'id': '187', 'type': 'pair', 'children': ['188', '189']}; {'id': '188', 'type': 'string', 'children': [], 'value': "'on_axis'"}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'on_axis'}; {'id': '190', 'type': 'pair', 'children': ['191', '192']}, {'id': '191', 'type': 'string', 'children': [], 'value': "'keepdims'"}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'keepdims'}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': '_copy'}; {'id': '200', 'type': 'argument_list', 'children': []}, {'id': '201', 'type': 'if_statement', 'children': ['202', '205']}; {'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': 'is'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '204', 'type': 'None', 'children': []}, {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'assignment', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'idx_axis'}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'index_of'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'first_op'}; {'id': '218', 'type': 'True', 'children': []}, {'id': '219', 'type': 'for_statement', 'children': ['220', '221', '222']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'op'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'operations'}; {'id': '222', 'type': 'block', 'children': ['223', '229', '250', '402', '406']}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '226', 'type': 'subscript', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '228', 'type': 'string', 'children': [], 'value': "'func'"}, {'id': '229', 'type': 'if_statement', 'children': ['230', '233']}; {'id': '230', 'type': 'comparison_operator', 'children': ['231', '232'], 'value': '=='}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '237', 'type': 'lambda', 'children': ['238', '241']}; {'id': '238', 'type': 'lambda_parameters', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '241', 'type': 'subscript', 'children': ['242', '249']}; {'id': '242', 'type': 'call', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '244', 'type': 'argument_list', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '249', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '250', 'type': 'for_statement', 'children': ['251', '252', '261']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '252', 'type': 'call', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'call', 'children': ['256', '259']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'number_of'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'string', 'children': [], 'value': "'trial'"}, {'id': '261', 'type': 'block', 'children': ['262', '285']}; {'id': '262', 'type': 'if_statement', 'children': ['263', '264', '274']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'first_op'}; {'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': 'x'}; {'id': '268', 'type': 'call', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}, {'id': '271', 'type': 'keyword_argument', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'trial'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '274', 'type': 'else_clause', 'children': ['275']}, {'id': '275', 'type': 'block', 'children': ['276']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'keyword_argument', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'trial'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '285', 'type': 'if_statement', 'children': ['286', '289', '376']}; {'id': '286', 'type': 'subscript', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '288', 'type': 'string', 'children': [], 'value': "'on_axis'"}, {'id': '289', 'type': 'block', 'children': ['290', '308']}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'call', 'children': ['292', '295']}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'lg'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'binary_operator', 'children': ['297', '304'], 'value': '+'}, {'id': '297', 'type': 'binary_operator', 'children': ['298', '303'], 'value': '+'}; {'id': '298', 'type': 'binary_operator', 'children': ['299', '300'], 'value': '+'}, {'id': '299', 'type': 'string', 'children': [], 'value': "'running '"}; {'id': '300', 'type': 'subscript', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '302', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '303', 'type': 'string', 'children': [], 'value': "' on '"}; {'id': '304', 'type': 'call', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '306', 'type': 'argument_list', 'children': ['307']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'idx_axis'}; {'id': '308', 'type': 'try_statement', 'children': ['309', '344']}, {'id': '309', 'type': 'block', 'children': ['310', '330']}; {'id': '310', 'type': 'if_statement', 'children': ['311', '314']}, {'id': '311', 'type': 'comparison_operator', 'children': ['312', '313'], 'value': '=='}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '314', 'type': 'block', 'children': ['315', '322']}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'lg'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'string', 'children': [], 'value': "'Diff has one-point of zero padding'"}; {'id': '322', 'type': 'expression_statement', 'children': ['323']}, {'id': '323', 'type': 'assignment', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '325', 'type': 'call', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': '_pad_one_axis_one_value'}, {'id': '327', 'type': 'argument_list', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'idx_axis'}; {'id': '330', 'type': 'expression_statement', 'children': ['331']}, {'id': '331', 'type': 'assignment', 'children': ['332', '337']}; {'id': '332', 'type': 'subscript', 'children': ['333', '336']}, {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '337', 'type': 'call', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '339', 'type': 'argument_list', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '341', 'type': 'keyword_argument', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'idx_axis'}; {'id': '344', 'type': 'except_clause', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '346', 'type': 'block', 'children': ['347']}, {'id': '347', 'type': 'raise_statement', 'children': ['348']}; {'id': '348', 'type': 'call', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '350', 'type': 'argument_list', 'children': ['351']}, {'id': '351', 'type': 'binary_operator', 'children': ['352', '375'], 'value': '+'}; {'id': '352', 'type': 'binary_operator', 'children': ['353', '360'], 'value': '+'}, {'id': '353', 'type': 'binary_operator', 'children': ['354', '357'], 'value': '+'}; {'id': '354', 'type': 'binary_operator', 'children': ['355', '356'], 'value': '+'}, {'id': '355', 'type': 'string', 'children': [], 'value': "'The axis '"}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '357', 'type': 'concatenated_string', 'children': ['358', '359']}; {'id': '358', 'type': 'string', 'children': [], 'value': "' does not '"}, {'id': '359', 'type': 'string', 'children': [], 'value': "'exist in ['"}; {'id': '360', 'type': 'call', 'children': ['361', '364']}, {'id': '361', 'type': 'attribute', 'children': ['362', '363']}; {'id': '362', 'type': 'string', 'children': [], 'value': "', '"}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '364', 'type': 'argument_list', 'children': ['365']}, {'id': '365', 'type': 'call', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '367', 'type': 'argument_list', 'children': ['368']}; {'id': '368', 'type': 'call', 'children': ['369', '374']}, {'id': '369', 'type': 'attribute', 'children': ['370', '373']}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '374', 'type': 'argument_list', 'children': []}, {'id': '375', 'type': 'string', 'children': [], 'value': "']'"}; {'id': '376', 'type': 'else_clause', 'children': ['377']}, {'id': '377', 'type': 'block', 'children': ['378', '391']}; {'id': '378', 'type': 'expression_statement', 'children': ['379']}, {'id': '379', 'type': 'call', 'children': ['380', '383']}; {'id': '380', 'type': 'attribute', 'children': ['381', '382']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'lg'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '383', 'type': 'argument_list', 'children': ['384']}; {'id': '384', 'type': 'binary_operator', 'children': ['385', '390'], 'value': '+'}, {'id': '385', 'type': 'binary_operator', 'children': ['386', '387'], 'value': '+'}; {'id': '386', 'type': 'string', 'children': [], 'value': "'running '"}, {'id': '387', 'type': 'subscript', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'op'}, {'id': '389', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '390', 'type': 'string', 'children': [], 'value': "' on each datapoint'"}, {'id': '391', 'type': 'expression_statement', 'children': ['392']}; {'id': '392', 'type': 'assignment', 'children': ['393', '398']}, {'id': '393', 'type': 'subscript', 'children': ['394', '397']}; {'id': '394', 'type': 'attribute', 'children': ['395', '396']}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '398', 'type': 'call', 'children': ['399', '400']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '400', 'type': 'argument_list', 'children': ['401']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '402', 'type': 'expression_statement', 'children': ['403']}, {'id': '403', 'type': 'assignment', 'children': ['404', '405']}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'first_op'}, {'id': '405', 'type': 'False', 'children': []}; {'id': '406', 'type': 'if_statement', 'children': ['407', '415']}, {'id': '407', 'type': 'boolean_operator', 'children': ['408', '411'], 'value': 'and'}; {'id': '408', 'type': 'subscript', 'children': ['409', '410']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '410', 'type': 'string', 'children': [], 'value': "'on_axis'"}, {'id': '411', 'type': 'not_operator', 'children': ['412']}; {'id': '412', 'type': 'subscript', 'children': ['413', '414']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'op'}; {'id': '414', 'type': 'string', 'children': [], 'value': "'keepdims'"}, {'id': '415', 'type': 'block', 'children': ['416']}; {'id': '416', 'type': 'delete_statement', 'children': ['417']}, {'id': '417', 'type': 'subscript', 'children': ['418', '421']}; {'id': '418', 'type': 'attribute', 'children': ['419', '420']}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '421', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '422', 'type': 'return_statement', 'children': ['423']}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'output'} | def math(data, operator=None, operator_name=None, axis=None):
if operator is not None and operator_name is not None:
raise TypeError('Parameters "operator" and "operator_name" are '
'mutually exclusive')
if operator_name is not None:
if isinstance(operator_name, str):
operator_name = (operator_name, )
operators = []
for one_operator_name in operator_name:
operators.append(eval(one_operator_name))
operator = tuple(operators)
if callable(operator):
operator = (operator, )
operations = []
for one_operator in operator:
on_axis = False
keepdims = True
try:
args = getfullargspec(one_operator).args
except TypeError:
lg.debug('func ' + str(one_operator) + ' is not a Python '
'function')
else:
if 'axis' in args:
on_axis = True
if axis is None:
raise TypeError('You need to specify an axis if you '
'use ' + one_operator.__name__ +
' (which applies to an axis)')
if 'keepdims' in args or one_operator in NOKEEPDIM:
keepdims = False
operations.append({'name': one_operator.__name__,
'func': one_operator,
'on_axis': on_axis,
'keepdims': keepdims,
})
output = data._copy()
if axis is not None:
idx_axis = data.index_of(axis)
first_op = True
for op in operations:
func = op['func']
if func == mode:
func = lambda x, axis: mode(x, axis=axis)[0]
for i in range(output.number_of('trial')):
if first_op:
x = data(trial=i)
else:
x = output(trial=i)
if op['on_axis']:
lg.debug('running ' + op['name'] + ' on ' + str(idx_axis))
try:
if func == diff:
lg.debug('Diff has one-point of zero padding')
x = _pad_one_axis_one_value(x, idx_axis)
output.data[i] = func(x, axis=idx_axis)
except IndexError:
raise ValueError('The axis ' + axis + ' does not '
'exist in [' +
', '.join(list(data.axis.keys())) + ']')
else:
lg.debug('running ' + op['name'] + ' on each datapoint')
output.data[i] = func(x)
first_op = False
if op['on_axis'] and not op['keepdims']:
del output.axis[axis]
return output |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'detect_Massimini2004'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dat_orig'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 's_freq'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '8', 'type': 'block', 'children': ['9', '19', '31', '42', '46', '129', '144']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'invert'}, {'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': 'dat_orig'}, {'id': '17', 'type': 'unary_operator', 'children': ['18'], 'value': '-'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'dat_orig'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'dat_det'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'transform_signal'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26', '27', '28']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'dat_orig'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'double_butter'"}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'det_filt'}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'above_zero'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'detect_events'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dat_det'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'above_thresh'"}, {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '41', 'type': 'float', 'children': [], 'value': '0.'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'sw_in_chan'}, {'id': '45', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'above_zero'}, {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51', '62']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'troughs'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'within_duration'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58', '59']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'above_zero'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'opts'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'trough_duration'}; {'id': '62', 'type': 'if_statement', 'children': ['63', '66']}, {'id': '63', 'type': 'comparison_operator', 'children': ['64', '65'], 'value': 'is'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'troughs'}, {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67', '78']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'troughs'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'select_peaks'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74', '75']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'dat_det'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'troughs'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'opts'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'max_trough_amp'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '82']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'is'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'troughs'}, {'id': '81', 'type': 'None', 'children': []}; {'id': '82', 'type': 'block', 'children': ['83', '93']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'events'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': '_add_halfwave'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90', '91', '92']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'dat_det'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'troughs'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 's_freq'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'opts'}, {'id': '93', 'type': 'if_statement', 'children': ['94', '98']}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'events'}; {'id': '98', 'type': 'block', 'children': ['99', '110', '119']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'events'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'within_duration'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '106', '107']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'events'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'opts'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'duration'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'events'}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'remove_straddlers'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '117', '118']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'events'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'sw_in_chan'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'make_slow_waves'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '126', '127', '128']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'events'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'dat_det'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '129', 'type': 'if_statement', 'children': ['130', '136']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '135'], 'value': '=='}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'sw_in_chan'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'lg'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'string', 'children': [], 'value': "'No slow wave found'"}; {'id': '144', 'type': 'return_statement', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'sw_in_chan'} | def detect_Massimini2004(dat_orig, s_freq, time, opts):
if opts.invert:
dat_orig = -dat_orig
dat_det = transform_signal(dat_orig, s_freq, 'double_butter',
opts.det_filt)
above_zero = detect_events(dat_det, 'above_thresh', value=0.)
sw_in_chan = []
if above_zero is not None:
troughs = within_duration(above_zero, time, opts.trough_duration)
if troughs is not None:
troughs = select_peaks(dat_det, troughs, opts.max_trough_amp)
if troughs is not None:
events = _add_halfwave(dat_det, troughs, s_freq, opts)
if len(events):
events = within_duration(events, time, opts.duration)
events = remove_straddlers(events, time, s_freq)
sw_in_chan = make_slow_waves(events, dat_det, time, s_freq)
if len(sw_in_chan) == 0:
lg.info('No slow wave found')
return sw_in_chan |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'low_cut'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'high_cut'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ftype'}, {'id': '19', 'type': 'string', 'children': [], 'value': "'butter'"}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Rs'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'notchfreq'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '50'}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'notchquality'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '25'}, {'id': '29', 'type': 'block', 'children': ['30', '38', '42', '135', '149', '158', '222', '230', '281']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'nyquist'}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '37'], 'value': '/'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '37', 'type': 'float', 'children': [], 'value': '2.'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'btype'}, {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'if_statement', 'children': ['43', '50', '81', '108']}, {'id': '43', 'type': 'boolean_operator', 'children': ['44', '47'], 'value': 'and'}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'low_cut'}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'high_cut'}, {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51', '67', '71']}, {'id': '51', 'type': 'if_statement', 'children': ['52', '59']}; {'id': '52', 'type': 'boolean_operator', 'children': ['53', '56'], 'value': 'or'}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '>'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'low_cut'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'nyquist'}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '>'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'high_cut'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'nyquist'}, {'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': 'concatenated_string', 'children': ['65', '66']}, {'id': '65', 'type': 'string', 'children': [], 'value': "'cutoff has to be less than Nyquist '"}; {'id': '66', 'type': 'string', 'children': [], 'value': "'frequency'"}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'btype'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'bandpass'"}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'Wn'}; {'id': '74', 'type': 'tuple', 'children': ['75', '78']}, {'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '/'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'low_cut'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'nyquist'}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '/'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'high_cut'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'nyquist'}, {'id': '81', 'type': 'elif_clause', 'children': ['82', '85']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'is'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'low_cut'}; {'id': '84', 'type': 'None', 'children': []}, {'id': '85', 'type': 'block', 'children': ['86', '98', '102']}; {'id': '86', 'type': 'if_statement', 'children': ['87', '90']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '>'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'low_cut'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'nyquist'}; {'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': 'concatenated_string', 'children': ['96', '97']}; {'id': '96', 'type': 'string', 'children': [], 'value': "'cutoff has to be less than Nyquist '"}, {'id': '97', 'type': 'string', 'children': [], 'value': "'frequency'"}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'btype'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'highpass'"}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'Wn'}, {'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '/'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'low_cut'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'nyquist'}; {'id': '108', 'type': 'elif_clause', 'children': ['109', '112']}, {'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'is'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'high_cut'}, {'id': '111', 'type': 'None', 'children': []}; {'id': '112', 'type': 'block', 'children': ['113', '125', '129']}, {'id': '113', 'type': 'if_statement', 'children': ['114', '117']}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '>'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'high_cut'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'nyquist'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'raise_statement', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'concatenated_string', 'children': ['123', '124']}, {'id': '123', 'type': 'string', 'children': [], 'value': "'cutoff has to be less than Nyquist '"}; {'id': '124', 'type': 'string', 'children': [], 'value': "'frequency'"}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'btype'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'lowpass'"}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'Wn'}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '/'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'high_cut'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'nyquist'}, {'id': '135', 'type': 'if_statement', 'children': ['136', '143']}; {'id': '136', 'type': 'boolean_operator', 'children': ['137', '140'], 'value': 'and'}, {'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'is'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'btype'}, {'id': '139', 'type': 'None', 'children': []}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': '!='}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'ftype'}; {'id': '142', 'type': 'string', 'children': [], 'value': "'notch'"}, {'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': 'TypeError'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'string', 'children': [], 'value': "'You should specify at least low_cut or high_cut'"}, {'id': '149', 'type': 'if_statement', 'children': ['150', '153']}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': 'is'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'Rs'}; {'id': '152', 'type': 'None', 'children': []}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'Rs'}, {'id': '157', 'type': 'integer', 'children': [], 'value': '40'}; {'id': '158', 'type': 'if_statement', 'children': ['159', '162', '182']}, {'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': '=='}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'ftype'}, {'id': '161', 'type': 'string', 'children': [], 'value': "'notch'"}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'b_a'}; {'id': '166', 'type': 'list_comprehension', 'children': ['167', '174']}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'iirnotch'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '173']}; {'id': '170', 'type': 'binary_operator', 'children': ['171', '172'], 'value': '/'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'w0'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'nyquist'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'notchquality'}; {'id': '174', 'type': 'for_in_clause', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'w0'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'arange'}; {'id': '178', 'type': 'argument_list', 'children': ['179', '180', '181']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'notchfreq'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'nyquist'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'notchfreq'}; {'id': '182', 'type': 'else_clause', 'children': ['183']}, {'id': '183', 'type': 'block', 'children': ['184', '204']}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'lg'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '196']}, {'id': '191', 'type': 'attribute', 'children': ['192', '195']}; {'id': '192', 'type': 'concatenated_string', 'children': ['193', '194']}, {'id': '193', 'type': 'string', 'children': [], 'value': "'order {0: 2}, Wn {1}, btype {2}, ftype {3}'"}; {'id': '194', 'type': 'string', 'children': [], 'value': "''"}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '198', '202', '203']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'Wn'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'btype'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'ftype'}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'b_a'}, {'id': '207', 'type': 'list', 'children': ['208'], 'value': '[iirfilter(order, Wn, btype=btype, ftype=ftype, rs=Rs), ]'}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'iirfilter'}; {'id': '210', 'type': 'argument_list', 'children': ['211', '212', '213', '216', '219']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'Wn'}, {'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'btype'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'btype'}; {'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'ftype'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'ftype'}, {'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'rs'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'Rs'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'fdata'}, {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': '_copy'}, {'id': '229', 'type': 'argument_list', 'children': []}; {'id': '230', 'type': 'for_statement', 'children': ['231', '232', '241']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '232', 'type': 'call', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}, {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'number_of'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'string', 'children': [], 'value': "'trial'"}, {'id': '241', 'type': 'block', 'children': ['242', '250', '273']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '245', 'type': 'subscript', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '250', 'type': 'for_statement', 'children': ['251', '254', '255']}, {'id': '251', 'type': 'pattern_list', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'b_a'}, {'id': '255', 'type': 'block', 'children': ['256']}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'filtfilt'}, {'id': '261', 'type': 'argument_list', 'children': ['262', '263', '264', '265']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '267', 'type': 'call', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'index_of'}, {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '280']}, {'id': '275', 'type': 'subscript', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'fdata'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '281', 'type': 'return_statement', 'children': ['282']} | def filter_(data, axis='time', low_cut=None, high_cut=None, order=4,
ftype='butter', Rs=None, notchfreq=50, notchquality=25):
nyquist = data.s_freq / 2.
btype = None
if low_cut is not None and high_cut is not None:
if low_cut > nyquist or high_cut > nyquist:
raise ValueError('cutoff has to be less than Nyquist '
'frequency')
btype = 'bandpass'
Wn = (low_cut / nyquist,
high_cut / nyquist)
elif low_cut is not None:
if low_cut > nyquist:
raise ValueError('cutoff has to be less than Nyquist '
'frequency')
btype = 'highpass'
Wn = low_cut / nyquist
elif high_cut is not None:
if high_cut > nyquist:
raise ValueError('cutoff has to be less than Nyquist '
'frequency')
btype = 'lowpass'
Wn = high_cut / nyquist
if btype is None and ftype != 'notch':
raise TypeError('You should specify at least low_cut or high_cut')
if Rs is None:
Rs = 40
if ftype == 'notch':
b_a = [iirnotch(w0 / nyquist, notchquality) for w0 in arange(notchfreq, nyquist, notchfreq)]
else:
lg.debug('order {0: 2}, Wn {1}, btype {2}, ftype {3}'
''.format(order, str(Wn), btype, ftype))
b_a = [iirfilter(order, Wn, btype=btype, ftype=ftype, rs=Rs), ]
fdata = data._copy()
for i in range(data.number_of('trial')):
x = data.data[i]
for b, a in b_a:
x = filtfilt(b, a, x, axis=data.index_of(axis))
fdata.data[i] = x
return fdata |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'select'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'trial'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'axes_to_select'}, {'id': '13', 'type': 'block', 'children': ['14', '31', '63', '105', '116', '139', '154', '158', '410']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '25']}, {'id': '15', 'type': 'boolean_operator', 'children': ['16', '19'], 'value': 'and'}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'trial'}; {'id': '18', 'type': 'None', 'children': []}, {'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': 'trial'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Iterable'}, {'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': 'TypeError'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'Trial needs to be iterable.'"}, {'id': '31', 'type': 'for_statement', 'children': ['32', '35', '40']}; {'id': '32', 'type': 'pattern_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'axis_to_select'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'axes_to_select'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'if_statement', 'children': ['42', '55']}; {'id': '42', 'type': 'parenthesized_expression', 'children': ['43'], 'value': '()'}, {'id': '43', 'type': 'boolean_operator', 'children': ['44', '50'], 'value': 'or'}; {'id': '44', 'type': 'not_operator', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'Iterable'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'str'}, {'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': 'TypeError'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '+'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'axis_to_select'}; {'id': '62', 'type': 'string', 'children': [], 'value': "' needs to be iterable.'"}, {'id': '63', 'type': 'if_statement', 'children': ['64', '67', '80']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'is'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'trial'}; {'id': '66', 'type': 'None', 'children': []}, {'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': 'trial'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'number_of'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'string', 'children': [], 'value': "'trial'"}; {'id': '80', 'type': 'else_clause', 'children': ['81']}, {'id': '81', 'type': 'block', 'children': ['82', '86']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'trial'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'trial'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '88', 'type': 'block', 'children': ['89']}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'trial'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'setdiff1d'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '104']}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'number_of'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'string', 'children': [], 'value': "'trial'"}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'trial'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': '_copy'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '115', 'type': 'False', 'children': []}; {'id': '116', 'type': 'for_statement', 'children': ['117', '118', '121']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'one_axis'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '129']}; {'id': '124', 'type': 'subscript', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'one_axis'}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '136']}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'trial'}; {'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'O'"}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '151']}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'trial'}, {'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '153', 'type': 'string', 'children': [], 'value': "'O'"}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'to_select'}, {'id': '157', 'type': 'dictionary', 'children': []}; {'id': '158', 'type': 'for_statement', 'children': ['159', '162', '166']}, {'id': '159', 'type': 'pattern_list', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'trial'}; {'id': '166', 'type': 'block', 'children': ['167', '179', '395']}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'lg'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'string', 'children': [], 'value': "'Selection on trial {0: 6}'"}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '179', 'type': 'for_statement', 'children': ['180', '181', '184']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'one_axis'}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '184', 'type': 'block', 'children': ['185', '195', '385']}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '188', 'type': 'subscript', 'children': ['189', '194']}, {'id': '189', 'type': 'subscript', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'one_axis'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '195', 'type': 'if_statement', 'children': ['196', '203', '360']}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': 'in'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'one_axis'}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'axes_to_select'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '202', 'type': 'argument_list', 'children': []}, {'id': '203', 'type': 'block', 'children': ['204', '210', '325', '336', '354']}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}, {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'axes_to_select'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'one_axis'}; {'id': '210', 'type': 'if_statement', 'children': ['211', '217', '222', '241']}, {'id': '211', 'type': 'comparison_operator', 'children': ['212', '216'], 'value': '=='}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}; {'id': '216', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'selected_values'}, {'id': '221', 'type': 'tuple', 'children': []}; {'id': '222', 'type': 'elif_clause', 'children': ['223', '230']}, {'id': '223', 'type': 'call', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '225', 'type': 'argument_list', 'children': ['226', '229']}; {'id': '226', 'type': 'subscript', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}; {'id': '228', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '230', 'type': 'block', 'children': ['231']}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'assignment', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'selected_values'}; {'id': '234', 'type': 'call', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '236', 'type': 'argument_list', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}; {'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '240', 'type': 'string', 'children': [], 'value': "'U'"}, {'id': '241', 'type': 'else_clause', 'children': ['242']}; {'id': '242', 'type': 'block', 'children': ['243', '319']}, {'id': '243', 'type': 'if_statement', 'children': ['244', '256', '270', '285', '300']}; {'id': '244', 'type': 'parenthesized_expression', 'children': ['245'], 'value': '()'}, {'id': '245', 'type': 'boolean_operator', 'children': ['246', '251'], 'value': 'and'}; {'id': '246', 'type': 'comparison_operator', 'children': ['247', '250'], 'value': 'is'}, {'id': '247', 'type': 'subscript', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}, {'id': '249', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '250', 'type': 'None', 'children': []}, {'id': '251', 'type': 'comparison_operator', 'children': ['252', '255'], 'value': 'is'}; {'id': '252', 'type': 'subscript', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}; {'id': '254', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '255', 'type': 'None', 'children': []}; {'id': '256', 'type': 'block', 'children': ['257']}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'assignment', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'bool_values'}; {'id': '260', 'type': 'call', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'ones'}; {'id': '262', 'type': 'argument_list', 'children': ['263', '267']}, {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '267', 'type': 'keyword_argument', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '270', 'type': 'elif_clause', 'children': ['271', '276']}, {'id': '271', 'type': 'comparison_operator', 'children': ['272', '275'], 'value': 'is'}; {'id': '272', 'type': 'subscript', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}; {'id': '274', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '275', 'type': 'None', 'children': []}; {'id': '276', 'type': 'block', 'children': ['277']}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'assignment', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'bool_values'}; {'id': '280', 'type': 'comparison_operator', 'children': ['281', '282'], 'value': '<'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '282', 'type': 'subscript', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}; {'id': '284', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '285', 'type': 'elif_clause', 'children': ['286', '291']}; {'id': '286', 'type': 'comparison_operator', 'children': ['287', '290'], 'value': 'is'}, {'id': '287', 'type': 'subscript', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}, {'id': '289', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '290', 'type': 'None', 'children': []}, {'id': '291', 'type': 'block', 'children': ['292']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'bool_values'}, {'id': '295', 'type': 'comparison_operator', 'children': ['296', '299'], 'value': '<='}; {'id': '296', 'type': 'subscript', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}; {'id': '298', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '300', 'type': 'else_clause', 'children': ['301']}, {'id': '301', 'type': 'block', 'children': ['302']}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'assignment', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'bool_values'}, {'id': '305', 'type': 'parenthesized_expression', 'children': ['306'], 'value': '()'}; {'id': '306', 'type': 'binary_operator', 'children': ['307', '313'], 'value': '&'}, {'id': '307', 'type': 'parenthesized_expression', 'children': ['308'], 'value': '()'}; {'id': '308', 'type': 'comparison_operator', 'children': ['309', '312'], 'value': '<='}, {'id': '309', 'type': 'subscript', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}, {'id': '311', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '313', 'type': 'parenthesized_expression', 'children': ['314'], 'value': '()'}; {'id': '314', 'type': 'comparison_operator', 'children': ['315', '316'], 'value': '<'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '316', 'type': 'subscript', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'values_to_select'}; {'id': '318', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '319', 'type': 'expression_statement', 'children': ['320']}; {'id': '320', 'type': 'assignment', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'selected_values'}; {'id': '322', 'type': 'subscript', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'bool_values'}, {'id': '325', 'type': 'if_statement', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'invert'}, {'id': '327', 'type': 'block', 'children': ['328']}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'assignment', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'selected_values'}, {'id': '331', 'type': 'call', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'setdiff1d'}, {'id': '333', 'type': 'argument_list', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'selected_values'}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}, {'id': '337', 'type': 'call', 'children': ['338', '341']}; {'id': '338', 'type': 'attribute', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'lg'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '341', 'type': 'argument_list', 'children': ['342']}; {'id': '342', 'type': 'call', 'children': ['343', '348']}, {'id': '343', 'type': 'attribute', 'children': ['344', '347']}; {'id': '344', 'type': 'concatenated_string', 'children': ['345', '346']}, {'id': '345', 'type': 'string', 'children': [], 'value': "'In axis {0}, selecting {1: 6} '"}; {'id': '346', 'type': 'string', 'children': [], 'value': "'values'"}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '348', 'type': 'argument_list', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'one_axis'}; {'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': 'selected_values'}; {'id': '354', 'type': 'expression_statement', 'children': ['355']}, {'id': '355', 'type': 'assignment', 'children': ['356', '359']}; {'id': '356', 'type': 'subscript', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'to_select'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'one_axis'}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'selected_values'}; {'id': '360', 'type': 'else_clause', 'children': ['361']}, {'id': '361', 'type': 'block', 'children': ['362', '375']}; {'id': '362', 'type': 'expression_statement', 'children': ['363']}, {'id': '363', 'type': 'call', 'children': ['364', '367']}; {'id': '364', 'type': 'attribute', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'lg'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '367', 'type': 'argument_list', 'children': ['368']}; {'id': '368', 'type': 'binary_operator', 'children': ['369', '372'], 'value': '+'}, {'id': '369', 'type': 'binary_operator', 'children': ['370', '371'], 'value': '+'}; {'id': '370', 'type': 'string', 'children': [], 'value': "'In axis '"}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'one_axis'}; {'id': '372', 'type': 'concatenated_string', 'children': ['373', '374']}, {'id': '373', 'type': 'string', 'children': [], 'value': "', selecting all the '"}; {'id': '374', 'type': 'string', 'children': [], 'value': "'values'"}, {'id': '375', 'type': 'expression_statement', 'children': ['376']}; {'id': '376', 'type': 'assignment', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'selected_values'}; {'id': '378', 'type': 'subscript', 'children': ['379', '384']}, {'id': '379', 'type': 'subscript', 'children': ['380', '383']}; {'id': '380', 'type': 'attribute', 'children': ['381', '382']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'one_axis'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '385', 'type': 'expression_statement', 'children': ['386']}; {'id': '386', 'type': 'assignment', 'children': ['387', '394']}, {'id': '387', 'type': 'subscript', 'children': ['388', '393']}; {'id': '388', 'type': 'subscript', 'children': ['389', '392']}, {'id': '389', 'type': 'attribute', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'one_axis'}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'cnt'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'selected_values'}, {'id': '395', 'type': 'expression_statement', 'children': ['396']}; {'id': '396', 'type': 'assignment', 'children': ['397', '402']}, {'id': '397', 'type': 'subscript', 'children': ['398', '401']}; {'id': '398', 'type': 'attribute', 'children': ['399', '400']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'cnt'}; {'id': '402', 'type': 'call', 'children': ['403', '404']}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '404', 'type': 'argument_list', 'children': ['405', '408']}, {'id': '405', 'type': 'keyword_argument', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'trial'}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '408', 'type': 'dictionary_splat', 'children': ['409']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'to_select'}; {'id': '410', 'type': 'return_statement', 'children': ['411']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'output'} | def select(data, trial=None, invert=False, **axes_to_select):
if trial is not None and not isinstance(trial, Iterable):
raise TypeError('Trial needs to be iterable.')
for axis_to_select, values_to_select in axes_to_select.items():
if (not isinstance(values_to_select, Iterable) or
isinstance(values_to_select, str)):
raise TypeError(axis_to_select + ' needs to be iterable.')
if trial is None:
trial = range(data.number_of('trial'))
else:
trial = trial
if invert:
trial = setdiff1d(range(data.number_of('trial')), trial)
output = data._copy(axis=False)
for one_axis in output.axis:
output.axis[one_axis] = empty(len(trial), dtype='O')
output.data = empty(len(trial), dtype='O')
to_select = {}
for cnt, i in enumerate(trial):
lg.debug('Selection on trial {0: 6}'.format(i))
for one_axis in output.axis:
values = data.axis[one_axis][i]
if one_axis in axes_to_select.keys():
values_to_select = axes_to_select[one_axis]
if len(values_to_select) == 0:
selected_values = ()
elif isinstance(values_to_select[0], str):
selected_values = asarray(values_to_select, dtype='U')
else:
if (values_to_select[0] is None and
values_to_select[1] is None):
bool_values = ones(len(values), dtype=bool)
elif values_to_select[0] is None:
bool_values = values < values_to_select[1]
elif values_to_select[1] is None:
bool_values = values_to_select[0] <= values
else:
bool_values = ((values_to_select[0] <= values) &
(values < values_to_select[1]))
selected_values = values[bool_values]
if invert:
selected_values = setdiff1d(values, selected_values)
lg.debug('In axis {0}, selecting {1: 6} '
'values'.format(one_axis,
len(selected_values)))
to_select[one_axis] = selected_values
else:
lg.debug('In axis ' + one_axis + ', selecting all the '
'values')
selected_values = data.axis[one_axis][i]
output.axis[one_axis][cnt] = selected_values
output.data[cnt] = data(trial=i, **to_select)
return output |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '49']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'fetch'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '13', '16', '19', '22', '25', '28', '31', '34', '37', '40', '43', '46']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dataset'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'annot'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '8', 'type': 'tuple', 'children': ['9', '10', '11', '12']}, {'id': '9', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '12', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'evt_type'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cycle'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'chan_full'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'epoch'}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'epoch_dur'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '30'}, {'id': '31', 'type': 'default_parameter', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'epoch_overlap'}, {'id': '33', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '34', 'type': 'default_parameter', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'epoch_step'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'default_parameter', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'reject_epoch'}, {'id': '39', 'type': 'False', 'children': []}; {'id': '40', 'type': 'default_parameter', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'reject_artf'}; {'id': '42', 'type': 'False', 'children': []}, {'id': '43', 'type': 'default_parameter', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'min_dur'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '46', 'type': 'default_parameter', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'buffer'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '49', 'type': 'block', 'children': ['50', '75', '102', '179', '186', '192']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'get_times'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57', '60', '63', '66', '69', '72']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'annot'}, {'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'evt_type'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'evt_type'}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'cycle'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'cycle'}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'chan_full'}, {'id': '69', 'type': 'keyword_argument', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'reject_epoch'}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'buffer'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'buffer'}, {'id': '75', 'type': 'if_statement', 'children': ['76', '79']}; {'id': '76', 'type': 'boolean_operator', 'children': ['77', '78'], 'value': 'and'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'reject_artf'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'for_statement', 'children': ['81', '82', '83']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'bund'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '89']}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'bund'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'times'"}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'remove_artf_evts'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '95', '96', '99']}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'bund'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'times'"}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'annot'}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'bund'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'chan'"}, {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'min_dur'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '102', 'type': 'if_statement', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'bundles'}; {'id': '104', 'type': 'block', 'children': ['105', '171']}, {'id': '105', 'type': 'if_statement', 'children': ['106', '109', '117', '159']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': '=='}, {'id': '107', 'type': 'string', 'children': [], 'value': "'locked'"}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'epoch'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '_divide_bundles'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '117', 'type': 'elif_clause', 'children': ['118', '121']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '=='}, {'id': '119', 'type': 'string', 'children': [], 'value': "'unlocked'"}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'epoch'}, {'id': '121', 'type': 'block', 'children': ['122', '142', '150']}; {'id': '122', 'type': 'if_statement', 'children': ['123', '126', '131']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': 'is'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'epoch_step'}, {'id': '125', 'type': 'None', 'children': []}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'step'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'epoch_step'}, {'id': '131', 'type': 'else_clause', 'children': ['132']}; {'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': 'step'}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '-'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'epoch_dur'}; {'id': '138', 'type': 'parenthesized_expression', 'children': ['139'], 'value': '()'}, {'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '*'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'epoch_dur'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'epoch_overlap'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': '_concat'}, {'id': '147', 'type': 'argument_list', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': '_find_intervals'}, {'id': '155', 'type': 'argument_list', 'children': ['156', '157', '158']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'epoch_dur'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'step'}, {'id': '159', 'type': 'elif_clause', 'children': ['160', '162']}; {'id': '160', 'type': 'not_operator', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'epoch'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'bundles'}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': '_concat'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'bundles'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'bundles'}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': '_longer_than'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'bundles'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'min_dur'}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'Segments'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'dataset'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'segments'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'segments'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'bundles'}; {'id': '192', 'type': 'return_statement', 'children': ['193']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'segments'} | def fetch(dataset, annot, cat=(0, 0, 0, 0), evt_type=None, stage=None,
cycle=None, chan_full=None, epoch=None, epoch_dur=30,
epoch_overlap=0, epoch_step=None, reject_epoch=False,
reject_artf=False, min_dur=0, buffer=0):
bundles = get_times(annot, evt_type=evt_type, stage=stage, cycle=cycle,
chan=chan_full, exclude=reject_epoch, buffer=buffer)
if reject_artf and bundles:
for bund in bundles:
bund['times'] = remove_artf_evts(bund['times'], annot,
bund['chan'], min_dur=0)
if bundles:
if 'locked' == epoch:
bundles = _divide_bundles(bundles)
elif 'unlocked' == epoch:
if epoch_step is not None:
step = epoch_step
else:
step = epoch_dur - (epoch_dur * epoch_overlap)
bundles = _concat(bundles, cat)
bundles = _find_intervals(bundles, epoch_dur, step)
elif not epoch:
bundles = _concat(bundles, cat)
bundles = _longer_than(bundles, min_dur)
segments = Segments(dataset)
segments.segments = bundles
return segments |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_times'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'annot'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'evt_type'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cycle'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'buffer'}; {'id': '22', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '23', 'type': 'block', 'children': ['24', '30', '36', '46', '56', '66', '113', '117', '124', '128', '250']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'getter'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'annot'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'get_epochs'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'last'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'annot'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'last_second'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '44', 'type': 'tuple', 'children': ['45']}, {'id': '45', 'type': 'None', 'children': []}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'cycle'}, {'id': '49', 'type': 'None', 'children': []}; {'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': 'cycle'}; {'id': '54', 'type': 'tuple', 'children': ['55']}, {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'if_statement', 'children': ['57', '60']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'is'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '59', 'type': 'None', 'children': []}; {'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': 'chan'}; {'id': '64', 'type': 'tuple', 'children': ['65']}, {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'if_statement', 'children': ['67', '70', '76', '104']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'is'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'evt_type'}, {'id': '69', 'type': 'None', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'evt_type'}; {'id': '74', 'type': 'tuple', 'children': ['75']}, {'id': '75', 'type': 'None', 'children': []}; {'id': '76', 'type': 'elif_clause', 'children': ['77', '84']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '83']}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'evt_type'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '84', 'type': 'block', 'children': ['85', '91']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'getter'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'annot'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'get_events'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '96']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': '!='}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '94', 'type': 'tuple', 'children': ['95']}, {'id': '95', 'type': 'None', 'children': []}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'string', 'children': [], 'value': "''"}; {'id': '104', 'type': 'else_clause', 'children': ['105']}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'lg'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'string', 'children': [], 'value': "'Event type must be list/tuple of str or None'"}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'qual'}; {'id': '116', 'type': 'None', 'children': []}, {'id': '117', 'type': 'if_statement', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'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': 'qual'}, {'id': '123', 'type': 'string', 'children': [], 'value': "'Good'"}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '127', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '128', 'type': 'for_statement', 'children': ['129', '130', '131']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'et'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'evt_type'}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'for_statement', 'children': ['133', '134', '135']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'ch'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'for_statement', 'children': ['137', '138', '139']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'cyc'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'cycle'}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'for_statement', 'children': ['141', '142', '143']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'ss'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '143', 'type': 'block', 'children': ['144', '148', '158', '180']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'st_input'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ss'}; {'id': '148', 'type': 'if_statement', 'children': ['149', '152']}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': 'is'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'ss'}, {'id': '151', 'type': 'None', 'children': []}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'st_input'}; {'id': '156', 'type': 'tuple', 'children': ['157']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'ss'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'evochs'}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'getter'}, {'id': '163', 'type': 'argument_list', 'children': ['164', '167', '170', '174', '177']}; {'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'et'}, {'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'cyc'}; {'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '172', 'type': 'tuple', 'children': ['173']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'ch'}; {'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'st_input'}, {'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'qual'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'qual'}; {'id': '180', 'type': 'if_statement', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'evochs'}; {'id': '182', 'type': 'block', 'children': ['183', '209', '224', '243']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '186', 'type': 'list_comprehension', 'children': ['187', '206']}, {'id': '187', 'type': 'tuple', 'children': ['188', '197']}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '196']}, {'id': '191', 'type': 'binary_operator', 'children': ['192', '195'], 'value': '-'}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'start'"}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'buffer'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '199', 'type': 'argument_list', 'children': ['200', '205']}; {'id': '200', 'type': 'binary_operator', 'children': ['201', '204'], 'value': '+'}, {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '203', 'type': 'string', 'children': [], 'value': "'end'"}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'buffer'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'last'}; {'id': '206', 'type': 'for_in_clause', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'evochs'}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '218', 'type': 'lambda', 'children': ['219', '221']}, {'id': '219', 'type': 'lambda_parameters', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '221', 'type': 'subscript', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '223', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'one_bundle'}, {'id': '227', 'type': 'dictionary', 'children': ['228', '231', '234', '237', '240']}; {'id': '228', 'type': 'pair', 'children': ['229', '230']}, {'id': '229', 'type': 'string', 'children': [], 'value': "'times'"}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '231', 'type': 'pair', 'children': ['232', '233']}; {'id': '232', 'type': 'string', 'children': [], 'value': "'stage'"}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'ss'}; {'id': '234', 'type': 'pair', 'children': ['235', '236']}, {'id': '235', 'type': 'string', 'children': [], 'value': "'cycle'"}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'cyc'}, {'id': '237', 'type': 'pair', 'children': ['238', '239']}; {'id': '238', 'type': 'string', 'children': [], 'value': "'chan'"}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'ch'}; {'id': '240', 'type': 'pair', 'children': ['241', '242']}, {'id': '241', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'et'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'one_bundle'}; {'id': '250', 'type': 'return_statement', 'children': ['251']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'bundles'} | def get_times(annot, evt_type=None, stage=None, cycle=None, chan=None,
exclude=False, buffer=0):
getter = annot.get_epochs
last = annot.last_second
if stage is None:
stage = (None,)
if cycle is None:
cycle = (None,)
if chan is None:
chan = (None,)
if evt_type is None:
evt_type = (None,)
elif isinstance(evt_type[0], str):
getter = annot.get_events
if chan != (None,):
chan.append('')
else:
lg.error('Event type must be list/tuple of str or None')
qual = None
if exclude:
qual = 'Good'
bundles = []
for et in evt_type:
for ch in chan:
for cyc in cycle:
for ss in stage:
st_input = ss
if ss is not None:
st_input = (ss,)
evochs = getter(name=et, time=cyc, chan=(ch,),
stage=st_input, qual=qual)
if evochs:
times = [(
max(e['start'] - buffer, 0),
min(e['end'] + buffer, last)) for e in evochs]
times = sorted(times, key=lambda x: x[0])
one_bundle = {'times': times,
'stage': ss,
'cycle': cyc,
'chan': ch,
'name': et}
bundles.append(one_bundle)
return bundles |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_concat'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '7', 'type': 'tuple', 'children': ['8', '9', '10', '11']}; {'id': '8', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '12', 'type': 'block', 'children': ['13', '29', '45', '61', '77', '81', '85', '89', '112', '128', '144', '154', '164', '174', '178', '299', '407', '419']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'list_comprehension', 'children': ['23', '26']}, {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'chan'"}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'cycle'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'list_comprehension', 'children': ['39', '42']}, {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '41', 'type': 'string', 'children': [], 'value': "'cycle'"}; {'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'list_comprehension', 'children': ['55', '58']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '57', 'type': 'string', 'children': [], 'value': "'stage'"}; {'id': '58', 'type': 'for_in_clause', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'evt_type'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'list_comprehension', 'children': ['71', '74']}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '73', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '74', 'type': 'for_in_clause', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'all_cycle'}; {'id': '80', 'type': 'None', 'children': []}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'all_stage'}; {'id': '84', 'type': 'None', 'children': []}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'all_evt_type'}; {'id': '88', 'type': 'None', 'children': []}, {'id': '89', 'type': 'if_statement', 'children': ['90', '95']}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '94'], 'value': 'is'}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'cycle'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '94', 'type': 'None', 'children': []}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'all_cycle'}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'list_comprehension', 'children': ['105', '109']}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '109', 'type': 'for_in_clause', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'cycle'}; {'id': '112', 'type': 'if_statement', 'children': ['113', '118']}, {'id': '113', 'type': 'comparison_operator', 'children': ['114', '117'], 'value': 'is'}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '117', 'type': 'None', 'children': []}; {'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': 'all_stage'}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': "', '"}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '128', 'type': 'if_statement', 'children': ['129', '134']}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': 'is'}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'evt_type'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '133', 'type': 'None', 'children': []}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'all_evt_type'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'string', 'children': [], 'value': "', '"}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'evt_type'}; {'id': '144', 'type': 'if_statement', 'children': ['145', '148']}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '147', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'cycle'}; {'id': '152', 'type': 'list', 'children': ['153'], 'value': '[all_cycle]'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'all_cycle'}; {'id': '154', 'type': 'if_statement', 'children': ['155', '158']}, {'id': '155', 'type': 'subscript', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '157', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '162', 'type': 'list', 'children': ['163'], 'value': '[all_stage]'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'all_stage'}; {'id': '164', 'type': 'if_statement', 'children': ['165', '168']}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '167', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'evt_type'}; {'id': '172', 'type': 'list', 'children': ['173'], 'value': '[all_evt_type]'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'all_evt_type'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'to_concat'}, {'id': '177', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '178', 'type': 'for_statement', 'children': ['179', '180', '181']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'ch'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'for_statement', 'children': ['183', '184', '185']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'cyc'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'cycle'}, {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'for_statement', 'children': ['187', '188', '189']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '189', 'type': 'block', 'children': ['190']}; {'id': '190', 'type': 'for_statement', 'children': ['191', '192', '193']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'et'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'evt_type'}, {'id': '193', 'type': 'block', 'children': ['194', '198', '258', '273', '292']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'new_times'}, {'id': '197', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '198', 'type': 'for_statement', 'children': ['199', '200', '201']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'bund'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'bundles'}, {'id': '201', 'type': 'block', 'children': ['202', '210', '220', '230', '240']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'chan_cond'}, {'id': '205', 'type': 'comparison_operator', 'children': ['206', '207'], 'value': '=='}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'ch'}, {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'bund'}, {'id': '209', 'type': 'string', 'children': [], 'value': "'chan'"}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'cyc_cond'}, {'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': 'in'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'cyc'}, {'id': '215', 'type': 'tuple', 'children': ['216', '219']}; {'id': '216', 'type': 'subscript', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'bund'}; {'id': '218', 'type': 'string', 'children': [], 'value': "'cycle'"}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'all_cycle'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'st_cond'}, {'id': '223', 'type': 'comparison_operator', 'children': ['224', '225'], 'value': 'in'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'st'}, {'id': '225', 'type': 'tuple', 'children': ['226', '229']}; {'id': '226', 'type': 'subscript', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'bund'}; {'id': '228', 'type': 'string', 'children': [], 'value': "'stage'"}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'all_stage'}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'et_cond'}, {'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': 'in'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'et'}, {'id': '235', 'type': 'tuple', 'children': ['236', '239']}; {'id': '236', 'type': 'subscript', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'bund'}; {'id': '238', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'all_evt_type'}; {'id': '240', 'type': 'if_statement', 'children': ['241', '248']}, {'id': '241', 'type': 'boolean_operator', 'children': ['242', '247'], 'value': 'and'}; {'id': '242', 'type': 'boolean_operator', 'children': ['243', '246'], 'value': 'and'}, {'id': '243', 'type': 'boolean_operator', 'children': ['244', '245'], 'value': 'and'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'chan_cond'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'cyc_cond'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'st_cond'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'et_cond'}; {'id': '248', 'type': 'block', 'children': ['249']}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'call', 'children': ['251', '254']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'new_times'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'subscript', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'bund'}, {'id': '257', 'type': 'string', 'children': [], 'value': "'times'"}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}, {'id': '259', 'type': 'assignment', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'new_times'}, {'id': '261', 'type': 'call', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '263', 'type': 'argument_list', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'new_times'}, {'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '267', 'type': 'lambda', 'children': ['268', '270']}; {'id': '268', 'type': 'lambda_parameters', 'children': ['269']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '270', 'type': 'subscript', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '272', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'new_bund'}; {'id': '276', 'type': 'dictionary', 'children': ['277', '280', '283', '286', '289']}, {'id': '277', 'type': 'pair', 'children': ['278', '279']}; {'id': '278', 'type': 'string', 'children': [], 'value': "'times'"}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'new_times'}; {'id': '280', 'type': 'pair', 'children': ['281', '282']}, {'id': '281', 'type': 'string', 'children': [], 'value': "'chan'"}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'ch'}, {'id': '283', 'type': 'pair', 'children': ['284', '285']}; {'id': '284', 'type': 'string', 'children': [], 'value': "'cycle'"}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'cyc'}; {'id': '286', 'type': 'pair', 'children': ['287', '288']}, {'id': '287', 'type': 'string', 'children': [], 'value': "'stage'"}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'st'}, {'id': '289', 'type': 'pair', 'children': ['290', '291']}; {'id': '290', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'et'}; {'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': 'to_concat'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'new_bund'}, {'id': '299', 'type': 'if_statement', 'children': ['300', '304']}; {'id': '300', 'type': 'not_operator', 'children': ['301']}, {'id': '301', 'type': 'subscript', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '303', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '304', 'type': 'block', 'children': ['305', '309', '403']}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'to_concat_new'}; {'id': '308', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '309', 'type': 'for_statement', 'children': ['310', '311', '312']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'bund'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'to_concat'}; {'id': '312', 'type': 'block', 'children': ['313', '317', '328', '332']}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'assignment', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'last'}; {'id': '316', 'type': 'None', 'children': []}, {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '324']}, {'id': '319', 'type': 'attribute', 'children': ['320', '323']}; {'id': '320', 'type': 'subscript', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'bund'}; {'id': '322', 'type': 'string', 'children': [], 'value': "'times'"}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '324', 'type': 'argument_list', 'children': ['325']}, {'id': '325', 'type': 'tuple', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'inf'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'inf'}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'assignment', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '331', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '332', 'type': 'for_statement', 'children': ['333', '336', '342']}, {'id': '333', 'type': 'pattern_list', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '336', 'type': 'call', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '338', 'type': 'argument_list', 'children': ['339']}, {'id': '339', 'type': 'subscript', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'bund'}, {'id': '341', 'type': 'string', 'children': [], 'value': "'times'"}; {'id': '342', 'type': 'block', 'children': ['343', '397']}, {'id': '343', 'type': 'if_statement', 'children': ['344', '347']}; {'id': '344', 'type': 'comparison_operator', 'children': ['345', '346'], 'value': 'is'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'last'}; {'id': '346', 'type': 'None', 'children': []}, {'id': '347', 'type': 'block', 'children': ['348']}; {'id': '348', 'type': 'if_statement', 'children': ['349', '360']}, {'id': '349', 'type': 'not_operator', 'children': ['350']}; {'id': '350', 'type': 'call', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'isclose'}; {'id': '352', 'type': 'argument_list', 'children': ['353', '356', '357']}, {'id': '353', 'type': 'subscript', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '355', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'last'}, {'id': '357', 'type': 'keyword_argument', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'abs_tol'}, {'id': '359', 'type': 'float', 'children': [], 'value': '0.01'}; {'id': '360', 'type': 'block', 'children': ['361', '372', '380', '386', '393']}, {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'assignment', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'new_times'}; {'id': '364', 'type': 'subscript', 'children': ['365', '368']}, {'id': '365', 'type': 'subscript', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'bund'}, {'id': '367', 'type': 'string', 'children': [], 'value': "'times'"}; {'id': '368', 'type': 'slice', 'children': ['369', '370', '371']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '370', 'type': 'colon', 'children': []}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '372', 'type': 'expression_statement', 'children': ['373']}, {'id': '373', 'type': 'assignment', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'new_bund'}, {'id': '375', 'type': 'call', 'children': ['376', '379']}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'bund'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '379', 'type': 'argument_list', 'children': []}; {'id': '380', 'type': 'expression_statement', 'children': ['381']}, {'id': '381', 'type': 'assignment', 'children': ['382', '385']}; {'id': '382', 'type': 'subscript', 'children': ['383', '384']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'new_bund'}; {'id': '384', 'type': 'string', 'children': [], 'value': "'times'"}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'new_times'}; {'id': '386', 'type': 'expression_statement', 'children': ['387']}, {'id': '387', 'type': 'call', 'children': ['388', '391']}; {'id': '388', 'type': 'attribute', 'children': ['389', '390']}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'to_concat_new'}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '391', 'type': 'argument_list', 'children': ['392']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'new_bund'}, {'id': '393', 'type': 'expression_statement', 'children': ['394']}; {'id': '394', 'type': 'assignment', 'children': ['395', '396']}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '397', 'type': 'expression_statement', 'children': ['398']}; {'id': '398', 'type': 'assignment', 'children': ['399', '400']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'last'}; {'id': '400', 'type': 'subscript', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '402', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '403', 'type': 'expression_statement', 'children': ['404']}; {'id': '404', 'type': 'assignment', 'children': ['405', '406']}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'to_concat'}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'to_concat_new'}, {'id': '407', 'type': 'expression_statement', 'children': ['408']}; {'id': '408', 'type': 'assignment', 'children': ['409', '410']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'to_concat'}; {'id': '410', 'type': 'list_comprehension', 'children': ['411', '412', '415']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '412', 'type': 'for_in_clause', 'children': ['413', '414']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'to_concat'}, {'id': '415', 'type': 'if_clause', 'children': ['416']}; {'id': '416', 'type': 'subscript', 'children': ['417', '418']}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '418', 'type': 'string', 'children': [], 'value': "'times'"}, {'id': '419', 'type': 'return_statement', 'children': ['420']} | def _concat(bundles, cat=(0, 0, 0, 0)):
chan = sorted(set([x['chan'] for x in bundles]))
cycle = sorted(set([x['cycle'] for x in bundles]))
stage = sorted(set([x['stage'] for x in bundles]))
evt_type = sorted(set([x['name'] for x in bundles]))
all_cycle = None
all_stage = None
all_evt_type = None
if cycle[0] is not None:
all_cycle = ', '.join([str(c) for c in cycle])
if stage[0] is not None:
all_stage = ', '.join(stage)
if evt_type[0] is not None:
all_evt_type = ', '.join(evt_type)
if cat[0]:
cycle = [all_cycle]
if cat[1]:
stage = [all_stage]
if cat[3]:
evt_type = [all_evt_type]
to_concat = []
for ch in chan:
for cyc in cycle:
for st in stage:
for et in evt_type:
new_times = []
for bund in bundles:
chan_cond = ch == bund['chan']
cyc_cond = cyc in (bund['cycle'], all_cycle)
st_cond = st in (bund['stage'], all_stage)
et_cond = et in (bund['name'], all_evt_type)
if chan_cond and cyc_cond and st_cond and et_cond:
new_times.extend(bund['times'])
new_times = sorted(new_times, key=lambda x: x[0])
new_bund = {'times': new_times,
'chan': ch,
'cycle': cyc,
'stage': st,
'name': et
}
to_concat.append(new_bund)
if not cat[2]:
to_concat_new = []
for bund in to_concat:
last = None
bund['times'].append((inf,inf))
start = 0
for i, j in enumerate(bund['times']):
if last is not None:
if not isclose(j[0], last, abs_tol=0.01):
new_times = bund['times'][start:i]
new_bund = bund.copy()
new_bund['times'] = new_times
to_concat_new.append(new_bund)
start = i
last = j[1]
to_concat = to_concat_new
to_concat = [x for x in to_concat if x['times']]
return to_concat |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'toggle_pac'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '93']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'is'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Pac'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '23', '34', '45', '56', '67', '78']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'pac_on'}; {'id': '14', 'type': 'call', 'children': ['15', '22']}, {'id': '15', 'type': 'attribute', 'children': ['16', '21']}; {'id': '16', 'type': 'subscript', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'pac_on'"}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'get_value'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '32']}, {'id': '25', 'type': 'attribute', 'children': ['26', '31']}; {'id': '26', 'type': 'subscript', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'prep'"}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pac_on'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '43']}; {'id': '36', 'type': 'attribute', 'children': ['37', '42']}, {'id': '37', 'type': 'subscript', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '41', 'type': 'string', 'children': [], 'value': "'box_metric'"}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'pac_on'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '54']}, {'id': '47', 'type': 'attribute', 'children': ['48', '53']}; {'id': '48', 'type': 'subscript', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'box_complex'"}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'pac_on'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '65']}; {'id': '58', 'type': 'attribute', 'children': ['59', '64']}, {'id': '59', 'type': 'subscript', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'box_surro'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'pac_on'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '76']}, {'id': '69', 'type': 'attribute', 'children': ['70', '75']}; {'id': '70', 'type': 'subscript', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'box_opts'"}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'pac_on'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '81']}, {'id': '79', 'type': 'not_operator', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'pac_on'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '91']}; {'id': '84', 'type': 'attribute', 'children': ['85', '90']}, {'id': '85', 'type': 'subscript', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'prep'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'set_value'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'False', 'children': []}, {'id': '93', 'type': 'if_statement', 'children': ['94', '99']}; {'id': '94', 'type': 'boolean_operator', 'children': ['95', '98'], 'value': 'and'}, {'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'is'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'Pac'}, {'id': '97', 'type': 'None', 'children': []}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'pac_on'}, {'id': '99', 'type': 'block', 'children': ['100', '106', '116', '126', '161', '172', '183', '242', '297', '309', '328', '340', '352', '362', '401', '414', '427']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'hilb_on'}, {'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': 'pac'}, {'id': '113', 'type': 'string', 'children': [], 'value': "'hilbert_on'"}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'isChecked'}, {'id': '115', 'type': 'argument_list', 'children': []}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'wav_on'}, {'id': '119', 'type': 'call', 'children': ['120', '125']}; {'id': '120', 'type': 'attribute', 'children': ['121', '124']}, {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '123', 'type': 'string', 'children': [], 'value': "'wavelet_on'"}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'isChecked'}, {'id': '125', 'type': 'argument_list', 'children': []}; {'id': '126', 'type': 'for_statement', 'children': ['127', '128', '135']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'button'}; {'id': '128', 'type': 'call', 'children': ['129', '134']}, {'id': '129', 'type': 'attribute', 'children': ['130', '133']}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'hilbert'"}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '134', 'type': 'argument_list', 'children': []}, {'id': '135', 'type': 'block', 'children': ['136', '145']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '143']}; {'id': '138', 'type': 'attribute', 'children': ['139', '142']}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'button'}, {'id': '141', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'hilb_on'}, {'id': '145', 'type': 'if_statement', 'children': ['146', '151']}; {'id': '146', 'type': 'comparison_operator', 'children': ['147', '150'], 'value': 'is'}, {'id': '147', 'type': 'subscript', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'button'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '150', 'type': 'None', 'children': []}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '159']}; {'id': '154', 'type': 'attribute', 'children': ['155', '158']}, {'id': '155', 'type': 'subscript', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'button'}, {'id': '157', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'hilb_on'}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '170']}, {'id': '163', 'type': 'attribute', 'children': ['164', '169']}; {'id': '164', 'type': 'subscript', 'children': ['165', '168']}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '167', 'type': 'string', 'children': [], 'value': "'wav_width'"}; {'id': '168', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'wav_on'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '181']}; {'id': '174', 'type': 'attribute', 'children': ['175', '180']}, {'id': '175', 'type': 'subscript', 'children': ['176', '179']}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'wav_width'"}, {'id': '179', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'wav_on'}, {'id': '183', 'type': 'if_statement', 'children': ['184', '195', '218']}; {'id': '184', 'type': 'comparison_operator', 'children': ['185', '192'], 'value': 'in'}, {'id': '185', 'type': 'call', 'children': ['186', '191']}; {'id': '186', 'type': 'attribute', 'children': ['187', '190']}, {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '189', 'type': 'string', 'children': [], 'value': "'metric'"}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'get_value'}, {'id': '191', 'type': 'argument_list', 'children': []}; {'id': '192', 'type': 'list', 'children': ['193', '194'], 'value': "[\n 'Kullback-Leibler Distance',\n 'Heights ratio']"}, {'id': '193', 'type': 'string', 'children': [], 'value': "'Kullback-Leibler Distance'"}; {'id': '194', 'type': 'string', 'children': [], 'value': "'Heights ratio'"}, {'id': '195', 'type': 'block', 'children': ['196', '207']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '205']}; {'id': '198', 'type': 'attribute', 'children': ['199', '204']}, {'id': '199', 'type': 'subscript', 'children': ['200', '203']}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'nbin'"}, {'id': '203', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'True', 'children': []}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '216']}, {'id': '209', 'type': 'attribute', 'children': ['210', '215']}; {'id': '210', 'type': 'subscript', 'children': ['211', '214']}, {'id': '211', 'type': 'subscript', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '213', 'type': 'string', 'children': [], 'value': "'nbin'"}; {'id': '214', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'True', 'children': []}; {'id': '218', 'type': 'else_clause', 'children': ['219']}, {'id': '219', 'type': 'block', 'children': ['220', '231']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'call', 'children': ['222', '229']}; {'id': '222', 'type': 'attribute', 'children': ['223', '228']}, {'id': '223', 'type': 'subscript', 'children': ['224', '227']}; {'id': '224', 'type': 'subscript', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '226', 'type': 'string', 'children': [], 'value': "'nbin'"}, {'id': '227', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'False', 'children': []}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '240']}, {'id': '233', 'type': 'attribute', 'children': ['234', '239']}; {'id': '234', 'type': 'subscript', 'children': ['235', '238']}, {'id': '235', 'type': 'subscript', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '237', 'type': 'string', 'children': [], 'value': "'nbin'"}; {'id': '238', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}, {'id': '241', 'type': 'False', 'children': []}; {'id': '242', 'type': 'if_statement', 'children': ['243', '248']}, {'id': '243', 'type': 'comparison_operator', 'children': ['244', '247'], 'value': '=='}; {'id': '244', 'type': 'subscript', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '246', 'type': 'string', 'children': [], 'value': "'metric'"}, {'id': '247', 'type': 'string', 'children': [], 'value': "'ndPac'"}; {'id': '248', 'type': 'block', 'children': ['249', '284']}, {'id': '249', 'type': 'for_statement', 'children': ['250', '251', '258']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'button'}, {'id': '251', 'type': 'call', 'children': ['252', '257']}; {'id': '252', 'type': 'attribute', 'children': ['253', '256']}, {'id': '253', 'type': 'subscript', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '255', 'type': 'string', 'children': [], 'value': "'surro'"}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '257', 'type': 'argument_list', 'children': []}; {'id': '258', 'type': 'block', 'children': ['259', '268']}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '266']}, {'id': '261', 'type': 'attribute', 'children': ['262', '265']}; {'id': '262', 'type': 'subscript', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'button'}; {'id': '264', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}, {'id': '267', 'type': 'False', 'children': []}; {'id': '268', 'type': 'if_statement', 'children': ['269', '274']}, {'id': '269', 'type': 'comparison_operator', 'children': ['270', '273'], 'value': 'is'}; {'id': '270', 'type': 'subscript', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'button'}; {'id': '272', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '273', 'type': 'None', 'children': []}; {'id': '274', 'type': 'block', 'children': ['275']}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'call', 'children': ['277', '282']}, {'id': '277', 'type': 'attribute', 'children': ['278', '281']}; {'id': '278', 'type': 'subscript', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'button'}; {'id': '280', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'False', 'children': []}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'call', 'children': ['286', '295']}; {'id': '286', 'type': 'attribute', 'children': ['287', '294']}, {'id': '287', 'type': 'subscript', 'children': ['288', '293']}; {'id': '288', 'type': 'subscript', 'children': ['289', '292']}, {'id': '289', 'type': 'subscript', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '291', 'type': 'string', 'children': [], 'value': "'surro'"}; {'id': '292', 'type': 'string', 'children': [], 'value': "'pval'"}, {'id': '293', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}, {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'True', 'children': []}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'ndpac_on'}; {'id': '300', 'type': 'comparison_operator', 'children': ['301', '308'], 'value': '=='}, {'id': '301', 'type': 'call', 'children': ['302', '307']}; {'id': '302', 'type': 'attribute', 'children': ['303', '306']}, {'id': '303', 'type': 'subscript', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '305', 'type': 'string', 'children': [], 'value': "'metric'"}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'get_value'}, {'id': '307', 'type': 'argument_list', 'children': []}; {'id': '308', 'type': 'string', 'children': [], 'value': "'ndPac'"}, {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'assignment', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'surro_on'}; {'id': '312', 'type': 'call', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'logical_and'}; {'id': '314', 'type': 'argument_list', 'children': ['315', '326']}, {'id': '315', 'type': 'comparison_operator', 'children': ['316', '323'], 'value': '!='}; {'id': '316', 'type': 'call', 'children': ['317', '322']}, {'id': '317', 'type': 'attribute', 'children': ['318', '321']}; {'id': '318', 'type': 'subscript', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '320', 'type': 'string', 'children': [], 'value': "'surro_method'"}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'get_value'}; {'id': '322', 'type': 'argument_list', 'children': []}, {'id': '323', 'type': 'concatenated_string', 'children': ['324', '325']}; {'id': '324', 'type': 'string', 'children': [], 'value': "''"}, {'id': '325', 'type': 'string', 'children': [], 'value': "'No surrogates'"}; {'id': '326', 'type': 'not_operator', 'children': ['327']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'ndpac_on'}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'assignment', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'norm_on'}, {'id': '331', 'type': 'comparison_operator', 'children': ['332', '339'], 'value': '!='}; {'id': '332', 'type': 'call', 'children': ['333', '338']}, {'id': '333', 'type': 'attribute', 'children': ['334', '337']}; {'id': '334', 'type': 'subscript', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '336', 'type': 'string', 'children': [], 'value': "'surro_norm'"}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'get_value'}; {'id': '338', 'type': 'argument_list', 'children': []}, {'id': '339', 'type': 'string', 'children': [], 'value': "'No normalization'"}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}, {'id': '341', 'type': 'assignment', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'blocks_on'}, {'id': '343', 'type': 'comparison_operator', 'children': ['344', '345'], 'value': 'in'}; {'id': '344', 'type': 'string', 'children': [], 'value': "'across time'"}, {'id': '345', 'type': 'call', 'children': ['346', '351']}; {'id': '346', 'type': 'attribute', 'children': ['347', '350']}, {'id': '347', 'type': 'subscript', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '349', 'type': 'string', 'children': [], 'value': "'surro_method'"}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'get_value'}, {'id': '351', 'type': 'argument_list', 'children': []}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}, {'id': '353', 'type': 'call', 'children': ['354', '359']}; {'id': '354', 'type': 'attribute', 'children': ['355', '358']}, {'id': '355', 'type': 'subscript', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '357', 'type': 'string', 'children': [], 'value': "'surro_method'"}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}, {'id': '359', 'type': 'argument_list', 'children': ['360']}; {'id': '360', 'type': 'not_operator', 'children': ['361']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'ndpac_on'}; {'id': '362', 'type': 'for_statement', 'children': ['363', '364', '371']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'button'}; {'id': '364', 'type': 'call', 'children': ['365', '370']}, {'id': '365', 'type': 'attribute', 'children': ['366', '369']}; {'id': '366', 'type': 'subscript', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '368', 'type': 'string', 'children': [], 'value': "'surro'"}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '370', 'type': 'argument_list', 'children': []}, {'id': '371', 'type': 'block', 'children': ['372', '383']}; {'id': '372', 'type': 'expression_statement', 'children': ['373']}, {'id': '373', 'type': 'call', 'children': ['374', '379']}; {'id': '374', 'type': 'attribute', 'children': ['375', '378']}, {'id': '375', 'type': 'subscript', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'button'}, {'id': '377', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}, {'id': '379', 'type': 'argument_list', 'children': ['380']}; {'id': '380', 'type': 'boolean_operator', 'children': ['381', '382'], 'value': 'and'}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'surro_on'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'norm_on'}, {'id': '383', 'type': 'if_statement', 'children': ['384', '389']}; {'id': '384', 'type': 'comparison_operator', 'children': ['385', '388'], 'value': 'is'}, {'id': '385', 'type': 'subscript', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'button'}, {'id': '387', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '388', 'type': 'None', 'children': []}, {'id': '389', 'type': 'block', 'children': ['390']}; {'id': '390', 'type': 'expression_statement', 'children': ['391']}, {'id': '391', 'type': 'call', 'children': ['392', '397']}; {'id': '392', 'type': 'attribute', 'children': ['393', '396']}, {'id': '393', 'type': 'subscript', 'children': ['394', '395']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'button'}, {'id': '395', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}, {'id': '397', 'type': 'argument_list', 'children': ['398']}; {'id': '398', 'type': 'boolean_operator', 'children': ['399', '400'], 'value': 'and'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'surro_on'}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'norm_on'}, {'id': '401', 'type': 'expression_statement', 'children': ['402']}; {'id': '402', 'type': 'call', 'children': ['403', '412']}, {'id': '403', 'type': 'attribute', 'children': ['404', '411']}; {'id': '404', 'type': 'subscript', 'children': ['405', '410']}, {'id': '405', 'type': 'subscript', 'children': ['406', '409']}; {'id': '406', 'type': 'subscript', 'children': ['407', '408']}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '408', 'type': 'string', 'children': [], 'value': "'surro'"}, {'id': '409', 'type': 'string', 'children': [], 'value': "'nblocks'"}; {'id': '410', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}; {'id': '412', 'type': 'argument_list', 'children': ['413']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'blocks_on'}; {'id': '414', 'type': 'expression_statement', 'children': ['415']}, {'id': '415', 'type': 'call', 'children': ['416', '425']}; {'id': '416', 'type': 'attribute', 'children': ['417', '424']}, {'id': '417', 'type': 'subscript', 'children': ['418', '423']}; {'id': '418', 'type': 'subscript', 'children': ['419', '422']}, {'id': '419', 'type': 'subscript', 'children': ['420', '421']}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '421', 'type': 'string', 'children': [], 'value': "'surro'"}; {'id': '422', 'type': 'string', 'children': [], 'value': "'nblocks'"}, {'id': '423', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}, {'id': '425', 'type': 'argument_list', 'children': ['426']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'blocks_on'}, {'id': '427', 'type': 'if_statement', 'children': ['428', '429']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'ndpac_on'}, {'id': '429', 'type': 'block', 'children': ['430', '439']}; {'id': '430', 'type': 'expression_statement', 'children': ['431']}, {'id': '431', 'type': 'call', 'children': ['432', '437']}; {'id': '432', 'type': 'attribute', 'children': ['433', '436']}, {'id': '433', 'type': 'subscript', 'children': ['434', '435']}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'pac'}, {'id': '435', 'type': 'string', 'children': [], 'value': "'surro_method'"}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'set_value'}, {'id': '437', 'type': 'argument_list', 'children': ['438']}; {'id': '438', 'type': 'string', 'children': [], 'value': "'No surrogates'"}, {'id': '439', 'type': 'expression_statement', 'children': ['440']}; {'id': '440', 'type': 'call', 'children': ['441', '450']}, {'id': '441', 'type': 'attribute', 'children': ['442', '449']}; {'id': '442', 'type': 'subscript', 'children': ['443', '448']}, {'id': '443', 'type': 'subscript', 'children': ['444', '447']}; {'id': '444', 'type': 'subscript', 'children': ['445', '446']}, {'id': '445', 'type': 'identifier', 'children': [], 'value': 'pac'}; {'id': '446', 'type': 'string', 'children': [], 'value': "'surro'"}, {'id': '447', 'type': 'string', 'children': [], 'value': "'pval'"}; {'id': '448', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'setEnabled'}; {'id': '450', 'type': 'argument_list', 'children': ['451']}, {'id': '451', 'type': 'True', 'children': []} | def toggle_pac(self):
if Pac is not None:
pac_on = self.pac['pac_on'].get_value()
self.pac['prep'].setEnabled(pac_on)
self.pac['box_metric'].setEnabled(pac_on)
self.pac['box_complex'].setEnabled(pac_on)
self.pac['box_surro'].setEnabled(pac_on)
self.pac['box_opts'].setEnabled(pac_on)
if not pac_on:
self.pac['prep'].set_value(False)
if Pac is not None and pac_on:
pac = self.pac
hilb_on = pac['hilbert_on'].isChecked()
wav_on = pac['wavelet_on'].isChecked()
for button in pac['hilbert'].values():
button[0].setEnabled(hilb_on)
if button[1] is not None:
button[1].setEnabled(hilb_on)
pac['wav_width'][0].setEnabled(wav_on)
pac['wav_width'][1].setEnabled(wav_on)
if pac['metric'].get_value() in [
'Kullback-Leibler Distance',
'Heights ratio']:
pac['nbin'][0].setEnabled(True)
pac['nbin'][1].setEnabled(True)
else:
pac['nbin'][0].setEnabled(False)
pac['nbin'][1].setEnabled(False)
if pac['metric'] == 'ndPac':
for button in pac['surro'].values():
button[0].setEnabled(False)
if button[1] is not None:
button[1].setEnabled(False)
pac['surro']['pval'][0].setEnabled(True)
ndpac_on = pac['metric'].get_value() == 'ndPac'
surro_on = logical_and(pac['surro_method'].get_value() != ''
'No surrogates', not ndpac_on)
norm_on = pac['surro_norm'].get_value() != 'No normalization'
blocks_on = 'across time' in pac['surro_method'].get_value()
pac['surro_method'].setEnabled(not ndpac_on)
for button in pac['surro'].values():
button[0].setEnabled(surro_on and norm_on)
if button[1] is not None:
button[1].setEnabled(surro_on and norm_on)
pac['surro']['nblocks'][0].setEnabled(blocks_on)
pac['surro']['nblocks'][1].setEnabled(blocks_on)
if ndpac_on:
pac['surro_method'].set_value('No surrogates')
pac['surro']['pval'][0].setEnabled(True) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_segments'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '28', '38', '50', '62', '66', '70', '120', '130', '137', '141', '145', '212', '224', '234', '270', '292', '320', '330', '378', '388', '398', '412', '468']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'chunk'}, {'id': '9', 'type': 'dictionary_comprehension', 'children': ['10', '17']}; {'id': '10', 'type': 'pair', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'isChecked'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'for_in_clause', 'children': ['18', '21']}; {'id': '18', 'type': 'pattern_list', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'lock_to_staging'}, {'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': 'lock_to_staging'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'get_value'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'epoch_dur'}, {'id': '41', 'type': 'call', 'children': ['42', '49']}; {'id': '42', 'type': 'attribute', 'children': ['43', '48']}, {'id': '43', 'type': 'subscript', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'epoch_param'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'dur'"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_value'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'epoch_overlap'}, {'id': '53', 'type': 'call', 'children': ['54', '61']}; {'id': '54', 'type': 'attribute', 'children': ['55', '60']}, {'id': '55', 'type': 'subscript', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'epoch_param'}, {'id': '59', 'type': 'string', 'children': [], 'value': "'overlap_val'"}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'epoch_step'}, {'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': 'epoch'}, {'id': '69', 'type': 'None', 'children': []}; {'id': '70', 'type': 'if_statement', 'children': ['71', '74']}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'chunk'}, {'id': '73', 'type': 'string', 'children': [], 'value': "'epoch'"}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'if_statement', 'children': ['76', '77', '82']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'lock_to_staging'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'epoch'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'locked'"}; {'id': '82', 'type': 'else_clause', 'children': ['83']}, {'id': '83', 'type': 'block', 'children': ['84', '88']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'epoch'}, {'id': '87', 'type': 'string', 'children': [], 'value': "'unlocked'"}; {'id': '88', 'type': 'if_statement', 'children': ['89', '98']}, {'id': '89', 'type': 'call', 'children': ['90', '97']}; {'id': '90', 'type': 'attribute', 'children': ['91', '96']}, {'id': '91', 'type': 'subscript', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'epoch_param'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'step'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'isChecked'}, {'id': '97', 'type': 'argument_list', 'children': []}; {'id': '98', 'type': 'block', 'children': ['99', '111']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'epoch_step'}; {'id': '102', 'type': 'call', 'children': ['103', '110']}, {'id': '103', 'type': 'attribute', 'children': ['104', '109']}; {'id': '104', 'type': 'subscript', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'epoch_param'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'step_val'"}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'get_value'}; {'id': '110', 'type': 'argument_list', 'children': []}, {'id': '111', 'type': 'if_statement', 'children': ['112', '115']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '<='}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'epoch_step'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'epoch_step'}, {'id': '119', 'type': 'float', 'children': [], 'value': '0.1'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'get_channels'}, {'id': '129', 'type': 'argument_list', 'children': []}; {'id': '130', 'type': 'if_statement', 'children': ['131', '135']}, {'id': '131', 'type': 'not_operator', 'children': ['132']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'return_statement', 'children': []}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'chan_full'}; {'id': '140', 'type': 'None', 'children': []}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'evt_type'}; {'id': '144', 'type': 'None', 'children': []}, {'id': '145', 'type': 'if_statement', 'children': ['146', '149']}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'chunk'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'event'"}, {'id': '149', 'type': 'block', 'children': ['150', '183', '193']}; {'id': '150', 'type': 'if_statement', 'children': ['151', '158']}, {'id': '151', 'type': 'call', 'children': ['152', '157']}; {'id': '152', 'type': 'attribute', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'evt_chan_only'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'get_value'}, {'id': '157', 'type': 'argument_list', 'children': []}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'chan_full'}; {'id': '162', 'type': 'list_comprehension', 'children': ['163', '178']}, {'id': '163', 'type': 'binary_operator', 'children': ['164', '175'], 'value': '+'}; {'id': '164', 'type': 'binary_operator', 'children': ['165', '168'], 'value': '+'}, {'id': '165', 'type': 'binary_operator', 'children': ['166', '167'], 'value': '+'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '167', 'type': 'string', 'children': [], 'value': "' ('"}; {'id': '168', 'type': 'call', 'children': ['169', '174']}, {'id': '169', 'type': 'attribute', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'idx_group'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'currentText'}; {'id': '174', 'type': 'argument_list', 'children': []}, {'id': '175', 'type': 'concatenated_string', 'children': ['176', '177']}; {'id': '176', 'type': 'string', 'children': [], 'value': "''"}, {'id': '177', 'type': 'string', 'children': [], 'value': "')'"}; {'id': '178', 'type': 'for_in_clause', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'evt_type'}; {'id': '186', 'type': 'call', 'children': ['187', '192']}, {'id': '187', 'type': 'attribute', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'idx_evt_type'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'selectedItems'}; {'id': '192', 'type': 'argument_list', 'children': []}, {'id': '193', 'type': 'if_statement', 'children': ['194', '196', '198']}; {'id': '194', 'type': 'not_operator', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'evt_type'}; {'id': '196', 'type': 'block', 'children': ['197']}, {'id': '197', 'type': 'return_statement', 'children': []}; {'id': '198', 'type': 'else_clause', 'children': ['199']}, {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'assignment', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'evt_type'}, {'id': '203', 'type': 'list_comprehension', 'children': ['204', '209']}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '208', 'type': 'argument_list', 'children': []}, {'id': '209', 'type': 'for_in_clause', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'evt_type'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'cycle'}, {'id': '215', 'type': 'assignment', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'cycle'}, {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'get_cycles'}, {'id': '223', 'type': 'argument_list', 'children': []}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '227', 'type': 'call', 'children': ['228', '233']}; {'id': '228', 'type': 'attribute', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'idx_stage'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'selectedItems'}, {'id': '233', 'type': 'argument_list', 'children': []}; {'id': '234', 'type': 'if_statement', 'children': ['235', '237', '246']}, {'id': '235', 'type': 'not_operator', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'assignment', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '241', 'type': 'assignment', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '245', 'type': 'None', 'children': []}; {'id': '246', 'type': 'else_clause', 'children': ['247']}, {'id': '247', 'type': 'block', 'children': ['248']}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'assignment', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '251', 'type': 'assignment', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '255', 'type': 'list_comprehension', 'children': ['256', '261']}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '260', 'type': 'argument_list', 'children': []}, {'id': '261', 'type': 'for_in_clause', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'x'}, {'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': 'idx_stage'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'selectedItems'}, {'id': '269', 'type': 'argument_list', 'children': []}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'assignment', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '273', 'type': 'dictionary_comprehension', 'children': ['274', '281']}; {'id': '274', 'type': 'pair', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '276', 'type': 'call', 'children': ['277', '280']}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'get_value'}; {'id': '280', 'type': 'argument_list', 'children': []}, {'id': '281', 'type': 'for_in_clause', 'children': ['282', '285']}; {'id': '282', 'type': 'pattern_list', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'v'}, {'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': 'cat'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '291', 'type': 'argument_list', 'children': []}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '295', 'type': 'tuple', 'children': ['296', '302', '308', '314']}; {'id': '296', 'type': 'call', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '298', 'type': 'argument_list', 'children': ['299']}, {'id': '299', 'type': 'subscript', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '301', 'type': 'string', 'children': [], 'value': "'cycle'"}; {'id': '302', 'type': 'call', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '304', 'type': 'argument_list', 'children': ['305']}, {'id': '305', 'type': 'subscript', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '307', 'type': 'string', 'children': [], 'value': "'stage'"}; {'id': '308', 'type': 'call', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}, {'id': '311', 'type': 'subscript', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '313', 'type': 'string', 'children': [], 'value': "'discontinuous'"}; {'id': '314', 'type': 'call', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'subscript', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '319', 'type': 'string', 'children': [], 'value': "'evt_type'"}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'assignment', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'reject_event'}, {'id': '323', 'type': 'call', 'children': ['324', '329']}; {'id': '324', 'type': 'attribute', 'children': ['325', '328']}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'reject_event'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'get_value'}, {'id': '329', 'type': 'argument_list', 'children': []}; {'id': '330', 'type': 'if_statement', 'children': ['331', '334', '363', '372']}, {'id': '331', 'type': 'comparison_operator', 'children': ['332', '333'], 'value': '=='}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'reject_event'}, {'id': '333', 'type': 'string', 'children': [], 'value': "'channel-specific'"}; {'id': '334', 'type': 'block', 'children': ['335', '359']}, {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'assignment', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'chan_full'}; {'id': '338', 'type': 'list_comprehension', 'children': ['339', '354']}, {'id': '339', 'type': 'binary_operator', 'children': ['340', '351'], 'value': '+'}; {'id': '340', 'type': 'binary_operator', 'children': ['341', '344'], 'value': '+'}, {'id': '341', 'type': 'binary_operator', 'children': ['342', '343'], 'value': '+'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '343', 'type': 'string', 'children': [], 'value': "' ('"}; {'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': 'idx_group'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'currentText'}; {'id': '350', 'type': 'argument_list', 'children': []}, {'id': '351', 'type': 'concatenated_string', 'children': ['352', '353']}; {'id': '352', 'type': 'string', 'children': [], 'value': "''"}, {'id': '353', 'type': 'string', 'children': [], 'value': "')'"}; {'id': '354', 'type': 'for_in_clause', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '359', 'type': 'expression_statement', 'children': ['360']}; {'id': '360', 'type': 'assignment', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'reject_artf'}; {'id': '362', 'type': 'True', 'children': []}, {'id': '363', 'type': 'elif_clause', 'children': ['364', '367']}; {'id': '364', 'type': 'comparison_operator', 'children': ['365', '366'], 'value': '=='}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'reject_event'}; {'id': '366', 'type': 'string', 'children': [], 'value': "'from any channel'"}, {'id': '367', 'type': 'block', 'children': ['368']}; {'id': '368', 'type': 'expression_statement', 'children': ['369']}, {'id': '369', 'type': 'assignment', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'reject_artf'}, {'id': '371', 'type': 'True', 'children': []}; {'id': '372', 'type': 'else_clause', 'children': ['373']}, {'id': '373', 'type': 'block', 'children': ['374']}; {'id': '374', 'type': 'expression_statement', 'children': ['375']}, {'id': '375', 'type': 'assignment', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'reject_artf'}, {'id': '377', 'type': 'False', 'children': []}; {'id': '378', 'type': 'expression_statement', 'children': ['379']}, {'id': '379', 'type': 'assignment', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'min_dur'}, {'id': '381', 'type': 'call', 'children': ['382', '387']}; {'id': '382', 'type': 'attribute', 'children': ['383', '386']}, {'id': '383', 'type': 'attribute', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'min_dur'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'get_value'}, {'id': '387', 'type': 'argument_list', 'children': []}; {'id': '388', 'type': 'expression_statement', 'children': ['389']}, {'id': '389', 'type': 'assignment', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'reject_epoch'}, {'id': '391', 'type': 'call', 'children': ['392', '397']}; {'id': '392', 'type': 'attribute', 'children': ['393', '396']}, {'id': '393', 'type': 'attribute', 'children': ['394', '395']}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'reject_epoch'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'get_value'}, {'id': '397', 'type': 'argument_list', 'children': []}; {'id': '398', 'type': 'expression_statement', 'children': ['399']}, {'id': '399', 'type': 'assignment', 'children': ['400', '403']}; {'id': '400', 'type': 'attribute', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '403', 'type': 'call', 'children': ['404', '407']}; {'id': '404', 'type': 'attribute', 'children': ['405', '406']}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'make_title'}, {'id': '407', 'type': 'argument_list', 'children': ['408', '409', '410', '411']}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'chan_full'}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'cycle'}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'evt_type'}; {'id': '412', 'type': 'expression_statement', 'children': ['413']}, {'id': '413', 'type': 'assignment', 'children': ['414', '415']}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'segments'}, {'id': '415', 'type': 'call', 'children': ['416', '417']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'fetch'}, {'id': '417', 'type': 'argument_list', 'children': ['418', '425', '432', '435', '438', '441', '444', '447', '450', '453', '456', '459', '462', '465']}; {'id': '418', 'type': 'attribute', 'children': ['419', '424']}, {'id': '419', 'type': 'attribute', 'children': ['420', '423']}; {'id': '420', 'type': 'attribute', 'children': ['421', '422']}, {'id': '421', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'dataset'}, {'id': '425', 'type': 'attribute', 'children': ['426', '431']}; {'id': '426', 'type': 'attribute', 'children': ['427', '430']}, {'id': '427', 'type': 'attribute', 'children': ['428', '429']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '429', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'notes'}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'annot'}; {'id': '432', 'type': 'keyword_argument', 'children': ['433', '434']}, {'id': '433', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'cat'}, {'id': '435', 'type': 'keyword_argument', 'children': ['436', '437']}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'evt_type'}, {'id': '437', 'type': 'identifier', 'children': [], 'value': 'evt_type'}; {'id': '438', 'type': 'keyword_argument', 'children': ['439', '440']}, {'id': '439', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '440', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '441', 'type': 'keyword_argument', 'children': ['442', '443']}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'cycle'}, {'id': '443', 'type': 'identifier', 'children': [], 'value': 'cycle'}; {'id': '444', 'type': 'keyword_argument', 'children': ['445', '446']}, {'id': '445', 'type': 'identifier', 'children': [], 'value': 'chan_full'}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'chan_full'}, {'id': '447', 'type': 'keyword_argument', 'children': ['448', '449']}; {'id': '448', 'type': 'identifier', 'children': [], 'value': 'epoch'}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'epoch'}; {'id': '450', 'type': 'keyword_argument', 'children': ['451', '452']}, {'id': '451', 'type': 'identifier', 'children': [], 'value': 'epoch_dur'}; {'id': '452', 'type': 'identifier', 'children': [], 'value': 'epoch_dur'}, {'id': '453', 'type': 'keyword_argument', 'children': ['454', '455']}; {'id': '454', 'type': 'identifier', 'children': [], 'value': 'epoch_overlap'}, {'id': '455', 'type': 'identifier', 'children': [], 'value': 'epoch_overlap'}; {'id': '456', 'type': 'keyword_argument', 'children': ['457', '458']}, {'id': '457', 'type': 'identifier', 'children': [], 'value': 'epoch_step'}; {'id': '458', 'type': 'identifier', 'children': [], 'value': 'epoch_step'}, {'id': '459', 'type': 'keyword_argument', 'children': ['460', '461']}; {'id': '460', 'type': 'identifier', 'children': [], 'value': 'reject_epoch'}, {'id': '461', 'type': 'identifier', 'children': [], 'value': 'reject_epoch'}; {'id': '462', 'type': 'keyword_argument', 'children': ['463', '464']}, {'id': '463', 'type': 'identifier', 'children': [], 'value': 'reject_artf'}; {'id': '464', 'type': 'identifier', 'children': [], 'value': 'reject_artf'}, {'id': '465', 'type': 'keyword_argument', 'children': ['466', '467']}; {'id': '466', 'type': 'identifier', 'children': [], 'value': 'min_dur'}, {'id': '467', 'type': 'identifier', 'children': [], 'value': 'min_dur'}; {'id': '468', 'type': 'return_statement', 'children': ['469']}, {'id': '469', 'type': 'identifier', 'children': [], 'value': 'segments'} | def get_segments(self):
chunk = {k: v.isChecked() for k, v in self.chunk.items()}
lock_to_staging = self.lock_to_staging.get_value()
epoch_dur = self.epoch_param['dur'].get_value()
epoch_overlap = self.epoch_param['overlap_val'].value()
epoch_step = None
epoch = None
if chunk['epoch']:
if lock_to_staging:
epoch = 'locked'
else:
epoch = 'unlocked'
if self.epoch_param['step'].isChecked():
epoch_step = self.epoch_param['step_val'].get_value()
if epoch_step <= 0:
epoch_step = 0.1
self.chan = self.get_channels()
if not self.chan:
return
chan_full = None
evt_type = None
if chunk['event']:
if self.evt_chan_only.get_value():
chan_full = [i + ' (' + self.idx_group.currentText() + ''
')' for i in self.chan]
evt_type = self.idx_evt_type.selectedItems()
if not evt_type:
return
else:
evt_type = [x.text() for x in evt_type]
cycle = self.cycle = self.get_cycles()
stage = self.idx_stage.selectedItems()
if not stage:
stage = self.stage = None
else:
stage = self.stage = [
x.text() for x in self.idx_stage.selectedItems()]
cat = {k: v.get_value() for k, v in self.cat.items()}
cat = (int(cat['cycle']), int(cat['stage']),
int(cat['discontinuous']), int(cat['evt_type']))
reject_event = self.reject_event.get_value()
if reject_event == 'channel-specific':
chan_full = [i + ' (' + self.idx_group.currentText() + ''
')' for i in self.chan]
reject_artf = True
elif reject_event == 'from any channel':
reject_artf = True
else:
reject_artf = False
min_dur = self.min_dur.get_value()
reject_epoch = self.reject_epoch.get_value()
self.title = self.make_title(chan_full, cycle, stage, evt_type)
segments = fetch(self.parent.info.dataset,
self.parent.notes.annot, cat=cat,
evt_type=evt_type, stage=stage, cycle=cycle,
chan_full=chan_full, epoch=epoch,
epoch_dur=epoch_dur, epoch_overlap=epoch_overlap,
epoch_step=epoch_step, reject_epoch=reject_epoch,
reject_artf=reject_artf, min_dur=min_dur)
return segments |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute_evt_params'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '12', '34', '58', '82', '104', '114', '124', '132', '138', '153', '175', '179', '183', '197', '270']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ev'}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'glob'}, {'id': '15', 'type': 'dictionary_comprehension', 'children': ['16', '23']}; {'id': '16', 'type': 'pair', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'get_value'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'for_in_clause', 'children': ['24', '27']}; {'id': '24', 'type': 'pattern_list', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '27', 'type': 'call', 'children': ['28', '33']}; {'id': '28', 'type': 'attribute', 'children': ['29', '32']}, {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'ev'}, {'id': '31', 'type': 'string', 'children': [], 'value': "'global'"}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '37', 'type': 'dictionary_comprehension', 'children': ['38', '47']}; {'id': '38', 'type': 'pair', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '40', 'type': 'call', 'children': ['41', '46']}, {'id': '41', 'type': 'attribute', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'get_value'}; {'id': '46', 'type': 'argument_list', 'children': []}, {'id': '47', 'type': 'for_in_clause', 'children': ['48', '51']}; {'id': '48', 'type': 'pattern_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'v'}, {'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': 'ev'}, {'id': '55', 'type': 'string', 'children': [], 'value': "'local'"}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'prep'}, {'id': '61', 'type': 'dictionary_comprehension', 'children': ['62', '71']}; {'id': '62', 'type': 'pair', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '64', 'type': 'call', 'children': ['65', '70']}, {'id': '65', 'type': 'attribute', 'children': ['66', '69']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'get_value'}; {'id': '70', 'type': 'argument_list', 'children': []}, {'id': '71', 'type': 'for_in_clause', 'children': ['72', '75']}; {'id': '72', 'type': 'pattern_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '75', 'type': 'call', 'children': ['76', '81']}; {'id': '76', 'type': 'attribute', 'children': ['77', '80']}, {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ev'}, {'id': '79', 'type': 'string', 'children': [], 'value': "'local'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '81', 'type': 'argument_list', 'children': []}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'slopes'}, {'id': '85', 'type': 'dictionary_comprehension', 'children': ['86', '93']}; {'id': '86', 'type': 'pair', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'get_value'}; {'id': '92', 'type': 'argument_list', 'children': []}, {'id': '93', 'type': 'for_in_clause', 'children': ['94', '97']}; {'id': '94', 'type': 'pattern_list', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '97', 'type': 'call', 'children': ['98', '103']}; {'id': '98', 'type': 'attribute', 'children': ['99', '102']}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'ev'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'sw'"}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '103', 'type': 'argument_list', 'children': []}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'f1'}, {'id': '107', 'type': 'call', 'children': ['108', '113']}; {'id': '108', 'type': 'attribute', 'children': ['109', '112']}, {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'ev'}, {'id': '111', 'type': 'string', 'children': [], 'value': "'f1'"}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'get_value'}, {'id': '113', 'type': 'argument_list', 'children': []}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'f2'}, {'id': '117', 'type': 'call', 'children': ['118', '123']}; {'id': '118', 'type': 'attribute', 'children': ['119', '122']}, {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ev'}, {'id': '121', 'type': 'string', 'children': [], 'value': "'f2'"}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'get_value'}, {'id': '123', 'type': 'argument_list', 'children': []}; {'id': '124', 'type': 'if_statement', 'children': ['125', '127']}, {'id': '125', 'type': 'not_operator', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'f2'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'f2'}, {'id': '131', 'type': 'None', 'children': []}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'band'}, {'id': '135', 'type': 'tuple', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'f1'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'f2'}; {'id': '138', 'type': 'if_statement', 'children': ['139', '148']}, {'id': '139', 'type': 'not_operator', 'children': ['140']}; {'id': '140', 'type': 'parenthesized_expression', 'children': ['141'], 'value': '()'}, {'id': '141', 'type': 'boolean_operator', 'children': ['142', '145'], 'value': 'or'}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'slopes'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'avg_slope'"}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'slopes'}, {'id': '147', 'type': 'string', 'children': [], 'value': "'max_slope'"}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'slopes'}; {'id': '152', 'type': 'None', 'children': []}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'evt_dat'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'event_params'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '162', '163', '166', '169', '172']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'band'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'band'}; {'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'slopes'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'slopes'}, {'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'prep'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'prep'}; {'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '178', 'type': 'None', 'children': []}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'density'}; {'id': '182', 'type': 'None', 'children': []}, {'id': '183', 'type': 'if_statement', 'children': ['184', '187']}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '186', 'type': 'string', 'children': [], 'value': "'count'"}, {'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': 'count'}, {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '197', 'type': 'if_statement', 'children': ['198', '201']}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '200', 'type': 'string', 'children': [], 'value': "'density'"}, {'id': '201', 'type': 'block', 'children': ['202', '208', '234', '256']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'epoch_dur'}, {'id': '205', 'type': 'subscript', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'glob'}, {'id': '207', 'type': 'string', 'children': [], 'value': "'density_per'"}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'poi'}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'get_times'}, {'id': '213', 'type': 'argument_list', 'children': ['214', '221', '226', '231']}; {'id': '214', 'type': 'attribute', 'children': ['215', '220']}, {'id': '215', 'type': 'attribute', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'notes'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'annot'}, {'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'stage'}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'stage'}; {'id': '226', 'type': 'keyword_argument', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'cycle'}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'cycle'}, {'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '233', 'type': 'True', 'children': []}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'total_dur'}, {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'list_comprehension', 'children': ['241', '248', '251']}, {'id': '241', 'type': 'binary_operator', 'children': ['242', '245'], 'value': '-'}; {'id': '242', 'type': 'subscript', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '244', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '245', 'type': 'subscript', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '247', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '248', 'type': 'for_in_clause', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'poi'}, {'id': '251', 'type': 'for_in_clause', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '253', 'type': 'subscript', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '255', 'type': 'string', 'children': [], 'value': "'times'"}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'density'}, {'id': '259', 'type': 'binary_operator', 'children': ['260', '266'], 'value': '/'}; {'id': '260', 'type': 'call', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '266', 'type': 'parenthesized_expression', 'children': ['267'], 'value': '()'}, {'id': '267', 'type': 'binary_operator', 'children': ['268', '269'], 'value': '/'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'total_dur'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'epoch_dur'}; {'id': '270', 'type': 'return_statement', 'children': ['271']}, {'id': '271', 'type': 'expression_list', 'children': ['272', '273', '274']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'evt_dat'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'count'} | def compute_evt_params(self):
ev = self.event
glob = {k: v.get_value() for k, v in ev['global'].items()}
params = {k: v[0].get_value() for k, v in ev['local'].items()}
prep = {k: v[1].get_value() for k, v in ev['local'].items()}
slopes = {k: v.get_value() for k, v in ev['sw'].items()}
f1 = ev['f1'].get_value()
f2 = ev['f2'].get_value()
if not f2:
f2 = None
band = (f1, f2)
if not (slopes['avg_slope'] or slopes['max_slope']):
slopes = None
evt_dat = event_params(self.data, params, band=band, slopes=slopes,
prep=prep, parent=self)
count = None
density = None
if glob['count']:
count = len(self.data)
if glob['density']:
epoch_dur = glob['density_per']
poi = get_times(self.parent.notes.annot, stage=self.stage,
cycle=self.cycle, exclude=True)
total_dur = sum([x[1] - x[0] for y in poi for x in y['times']])
density = len(self.data) / (total_dur / epoch_dur)
return evt_dat, count, density |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'detect_format'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '5', 'type': 'block', 'children': ['6', '13']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'Path'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '13', 'type': 'if_statement', 'children': ['14', '19', '105']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'is_dir'}; {'id': '18', 'type': 'argument_list', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'if_statement', 'children': ['21', '40', '43', '55', '67', '80', '93']}, {'id': '21', 'type': 'boolean_operator', 'children': ['22', '31'], 'value': 'and'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'glob'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'*.stc'"}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'list'}, {'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': 'filename'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'string', 'children': [], 'value': "'*.erd'"}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'Ktlx'}, {'id': '43', 'type': 'elif_clause', 'children': ['44', '52']}; {'id': '44', 'type': 'call', 'children': ['45', '51']}, {'id': '45', 'type': 'attribute', 'children': ['46', '50']}; {'id': '46', 'type': 'parenthesized_expression', 'children': ['47'], 'value': '()'}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '/'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '49', 'type': 'string', 'children': [], 'value': "'patient.info'"}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'return_statement', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'Moberg'}, {'id': '55', 'type': 'elif_clause', 'children': ['56', '64']}; {'id': '56', 'type': 'call', 'children': ['57', '63']}, {'id': '57', 'type': 'attribute', 'children': ['58', '62']}; {'id': '58', 'type': 'parenthesized_expression', 'children': ['59'], 'value': '()'}, {'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '/'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '61', 'type': 'string', 'children': [], 'value': "'info.xml'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'EgiMff'}, {'id': '67', 'type': 'elif_clause', 'children': ['68', '77']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'glob'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'*.openephys'"}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'return_statement', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'OpenEphys'}; {'id': '80', 'type': 'elif_clause', 'children': ['81', '90']}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'string', 'children': [], 'value': "'*.txt'"}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'return_statement', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'Text'}, {'id': '93', 'type': 'else_clause', 'children': ['94']}; {'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': 'UnrecognizedFormat'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '+'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'Unrecognized format for directory '"}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '105', 'type': 'else_clause', 'children': ['106']}; {'id': '106', 'type': 'block', 'children': ['107', '116', '129', '138', '147', '156', '171', '195', '238']}, {'id': '107', 'type': 'if_statement', 'children': ['108', '113']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '112'], 'value': '=='}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'.won'"}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'return_statement', 'children': ['115']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'Wonambi'}; {'id': '116', 'type': 'if_statement', 'children': ['117', '126']}, {'id': '117', 'type': 'comparison_operator', 'children': ['118', '125'], 'value': '=='}; {'id': '118', 'type': 'call', 'children': ['119', '124']}, {'id': '119', 'type': 'attribute', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '124', 'type': 'argument_list', 'children': []}, {'id': '125', 'type': 'string', 'children': [], 'value': "'.trc'"}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'return_statement', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'Micromed'}, {'id': '129', 'type': 'if_statement', 'children': ['130', '135']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '134'], 'value': '=='}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '134', 'type': 'string', 'children': [], 'value': "'.set'"}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'return_statement', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'EEGLAB'}; {'id': '138', 'type': 'if_statement', 'children': ['139', '144']}, {'id': '139', 'type': 'comparison_operator', 'children': ['140', '143'], 'value': '=='}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '143', 'type': 'string', 'children': [], 'value': "'.edf'"}; {'id': '144', 'type': 'block', 'children': ['145']}, {'id': '145', 'type': 'return_statement', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'Edf'}, {'id': '147', 'type': 'if_statement', 'children': ['148', '153']}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '152'], 'value': '=='}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'.abf'"}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'return_statement', 'children': ['155']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'Abf'}; {'id': '156', 'type': 'if_statement', 'children': ['157', '168']}, {'id': '157', 'type': 'boolean_operator', 'children': ['158', '163'], 'value': 'or'}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '162'], 'value': '=='}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'.vhdr'"}, {'id': '163', 'type': 'comparison_operator', 'children': ['164', '167'], 'value': '=='}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '167', 'type': 'string', 'children': [], 'value': "'.eeg'"}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'return_statement', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'BrainVision'}, {'id': '171', 'type': 'if_statement', 'children': ['172', '177']}; {'id': '172', 'type': 'comparison_operator', 'children': ['173', '176'], 'value': '=='}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '176', 'type': 'string', 'children': [], 'value': "'.dat'"}, {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'try_statement', 'children': ['179', '185', '191']}, {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': '_read_header_length'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '185', 'type': 'except_clause', 'children': ['186', '189']}; {'id': '186', 'type': 'tuple', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '189', 'type': 'block', 'children': ['190']}; {'id': '190', 'type': 'pass_statement', 'children': []}, {'id': '191', 'type': 'else_clause', 'children': ['192']}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'return_statement', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'BCI2000'}, {'id': '195', 'type': 'with_statement', 'children': ['196', '207']}; {'id': '196', 'type': 'with_clause', 'children': ['197']}, {'id': '197', 'type': 'with_item', 'children': ['198']}; {'id': '198', 'type': 'as_pattern', 'children': ['199', '205']}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'string', 'children': [], 'value': "'rb'"}, {'id': '205', 'type': 'as_pattern_target', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '207', 'type': 'block', 'children': ['208', '217']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'file_header'}, {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'integer', 'children': [], 'value': '8'}, {'id': '217', 'type': 'if_statement', 'children': ['218', '224', '227']}; {'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': 'in'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'file_header'}; {'id': '220', 'type': 'tuple', 'children': ['221', '222', '223']}, {'id': '221', 'type': 'string', 'children': [], 'value': "b'NEURALCD'"}; {'id': '222', 'type': 'string', 'children': [], 'value': "b'NEURALSG'"}, {'id': '223', 'type': 'string', 'children': [], 'value': "b'NEURALEV'"}; {'id': '224', 'type': 'block', 'children': ['225']}, {'id': '225', 'type': 'return_statement', 'children': ['226']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'BlackRock'}, {'id': '227', 'type': 'elif_clause', 'children': ['228', '235']}; {'id': '228', 'type': 'comparison_operator', 'children': ['229', '234'], 'value': '=='}, {'id': '229', 'type': 'subscript', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'file_header'}, {'id': '231', 'type': 'slice', 'children': ['232', '233']}; {'id': '232', 'type': 'colon', 'children': []}, {'id': '233', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '234', 'type': 'string', 'children': [], 'value': "b'MATLAB'"}, {'id': '235', 'type': 'block', 'children': ['236']}; {'id': '236', 'type': 'return_statement', 'children': ['237']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'FieldTrip'}; {'id': '238', 'type': 'if_statement', 'children': ['239', '248', '282']}, {'id': '239', 'type': 'comparison_operator', 'children': ['240', '247'], 'value': '=='}; {'id': '240', 'type': 'call', 'children': ['241', '246']}, {'id': '241', 'type': 'attribute', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '246', 'type': 'argument_list', 'children': []}, {'id': '247', 'type': 'string', 'children': [], 'value': "'.txt'"}; {'id': '248', 'type': 'block', 'children': ['249']}, {'id': '249', 'type': 'with_statement', 'children': ['250', '261']}; {'id': '250', 'type': 'with_clause', 'children': ['251']}, {'id': '251', 'type': 'with_item', 'children': ['252']}; {'id': '252', 'type': 'as_pattern', 'children': ['253', '259']}, {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'string', 'children': [], 'value': "'rt'"}, {'id': '259', 'type': 'as_pattern_target', 'children': ['260']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '261', 'type': 'block', 'children': ['262', '270']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'assignment', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'first_line'}, {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'readline'}, {'id': '269', 'type': 'argument_list', 'children': []}; {'id': '270', 'type': 'if_statement', 'children': ['271', '279']}, {'id': '271', 'type': 'comparison_operator', 'children': ['272', '273'], 'value': 'in'}; {'id': '272', 'type': 'string', 'children': [], 'value': "'.rr'"}, {'id': '273', 'type': 'subscript', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'first_line'}, {'id': '275', 'type': 'slice', 'children': ['276', '278']}; {'id': '276', 'type': 'unary_operator', 'children': ['277'], 'value': '-'}, {'id': '277', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '278', 'type': 'colon', 'children': []}, {'id': '279', 'type': 'block', 'children': ['280']}; {'id': '280', 'type': 'return_statement', 'children': ['281']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'LyonRRI'}; {'id': '282', 'type': 'else_clause', 'children': ['283']}, {'id': '283', 'type': 'block', 'children': ['284']}; {'id': '284', 'type': 'raise_statement', 'children': ['285']}, {'id': '285', 'type': 'call', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'UnrecognizedFormat'}, {'id': '287', 'type': 'argument_list', 'children': ['288']}; {'id': '288', 'type': 'binary_operator', 'children': ['289', '290'], 'value': '+'}, {'id': '289', 'type': 'string', 'children': [], 'value': "'Unrecognized format for file '"}; {'id': '290', 'type': 'call', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'filename'} | def detect_format(filename):
filename = Path(filename)
if filename.is_dir():
if list(filename.glob('*.stc')) and list(filename.glob('*.erd')):
return Ktlx
elif (filename / 'patient.info').exists():
return Moberg
elif (filename / 'info.xml').exists():
return EgiMff
elif list(filename.glob('*.openephys')):
return OpenEphys
elif list(filename.glob('*.txt')):
return Text
else:
raise UnrecognizedFormat('Unrecognized format for directory ' +
str(filename))
else:
if filename.suffix == '.won':
return Wonambi
if filename.suffix.lower() == '.trc':
return Micromed
if filename.suffix == '.set':
return EEGLAB
if filename.suffix == '.edf':
return Edf
if filename.suffix == '.abf':
return Abf
if filename.suffix == '.vhdr' or filename.suffix == '.eeg':
return BrainVision
if filename.suffix == '.dat':
try:
_read_header_length(filename)
except (AttributeError, ValueError):
pass
else:
return BCI2000
with filename.open('rb') as f:
file_header = f.read(8)
if file_header in (b'NEURALCD', b'NEURALSG', b'NEURALEV'):
return BlackRock
elif file_header[:6] == b'MATLAB':
return FieldTrip
if filename.suffix.lower() == '.txt':
with filename.open('rt') as f:
first_line = f.readline()
if '.rr' in first_line[-4:]:
return LyonRRI
else:
raise UnrecognizedFormat('Unrecognized format for file ' +
str(filename)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_videos'}, {'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': 'begtime'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'endtime'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '29', '44', '61', '76', '88']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '18']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'begtime'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'begtime'}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '-'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'begtime'}; {'id': '24', 'type': 'subscript', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'start_time'"}, {'id': '29', 'type': 'if_statement', 'children': ['30', '35']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'begtime'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'timedelta'}, {'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': 'begtime'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'begtime'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'total_seconds'}, {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'if_statement', 'children': ['45', '50']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'endtime'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'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': 'endtime'}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '56'], 'value': '-'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'endtime'}; {'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': 'header'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'start_time'"}, {'id': '61', 'type': 'if_statement', 'children': ['62', '67']}; {'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': 'endtime'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'timedelta'}, {'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': 'endtime'}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'endtime'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'total_seconds'}, {'id': '75', 'type': 'argument_list', 'children': []}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'videos'}, {'id': '79', 'type': 'call', 'children': ['80', '85']}; {'id': '80', 'type': 'attribute', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'dataset'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'return_videos'}, {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'begtime'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'endtime'}; {'id': '88', 'type': 'return_statement', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'videos'} | def read_videos(self, begtime=None, endtime=None):
if isinstance(begtime, datetime):
begtime = begtime - self.header['start_time']
if isinstance(begtime, timedelta):
begtime = begtime.total_seconds()
if isinstance(endtime, datetime):
endtime = endtime - self.header['start_time']
if isinstance(endtime, timedelta):
endtime = endtime.total_seconds()
videos = self.dataset.return_videos(begtime, endtime)
return videos |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_data'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'begtime'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'endtime'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'begsam'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'endsam'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 's_freq'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'block', 'children': ['24', '30', '40', '55', '68', '88', '92', '116', '133', '146', '163', '200', '237', '250', '263', '281', '288', '302', '316', '328', '451']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'ChanTime'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'start_time'}, {'id': '35', 'type': 'subscript', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '39', 'type': 'string', 'children': [], 'value': "'start_time'"}; {'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': 'data'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '47', 'type': 'conditional_expression', 'children': ['48', '49', '50'], 'value': 'if'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 's_freq'}; {'id': '50', 'type': 'subscript', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'s_freq'"}, {'id': '55', 'type': 'if_statement', 'children': ['56', '59']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'is'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '58', 'type': 'None', 'children': []}, {'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': 'chan'}, {'id': '63', 'type': 'subscript', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '67', 'type': 'string', 'children': [], 'value': "'chan_name'"}; {'id': '68', 'type': 'if_statement', 'children': ['69', '82']}, {'id': '69', 'type': 'not_operator', 'children': ['70']}; {'id': '70', 'type': 'parenthesized_expression', 'children': ['71'], 'value': '()'}, {'id': '71', 'type': 'boolean_operator', 'children': ['72', '77'], 'value': 'or'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'raise_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'string', 'children': [], 'value': '\'Parameter "chan" should be a list\''}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'add_ref'}, {'id': '91', 'type': 'False', 'children': []}; {'id': '92', 'type': 'if_statement', 'children': ['93', '96']}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'in'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'_REF'"}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '96', 'type': 'block', 'children': ['97', '101']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'add_ref'}; {'id': '100', 'type': 'True', 'children': []}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '107']}, {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '105', 'type': 'slice', 'children': ['106']}; {'id': '106', 'type': 'colon', 'children': []}, {'id': '107', 'type': 'list_comprehension', 'children': ['108', '109', '112']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '109', 'type': 'for_in_clause', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '112', 'type': 'if_clause', 'children': ['113']}, {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': '!='}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '115', 'type': 'string', 'children': [], 'value': "'_REF'"}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'idx_chan'}, {'id': '119', 'type': 'list_comprehension', 'children': ['120', '130']}; {'id': '120', 'type': 'call', 'children': ['121', '128']}, {'id': '121', 'type': 'attribute', 'children': ['122', '127']}; {'id': '122', 'type': 'subscript', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'chan_name'"}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '130', 'type': 'for_in_clause', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '133', 'type': 'if_statement', 'children': ['134', '141']}; {'id': '134', 'type': 'boolean_operator', 'children': ['135', '138'], 'value': 'and'}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': 'is'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'begtime'}, {'id': '137', 'type': 'None', 'children': []}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': 'is'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'begsam'}; {'id': '140', 'type': 'None', 'children': []}, {'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': 'begsam'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '154']}, {'id': '147', 'type': 'boolean_operator', 'children': ['148', '151'], 'value': 'and'}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'is'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'endtime'}; {'id': '150', 'type': 'None', 'children': []}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'is'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'endsam'}, {'id': '153', 'type': 'None', 'children': []}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'endsam'}; {'id': '158', 'type': 'subscript', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'header'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'n_samples'"}, {'id': '163', 'type': 'if_statement', 'children': ['164', '167']}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': 'is'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'begtime'}; {'id': '166', 'type': 'None', 'children': []}, {'id': '167', 'type': 'block', 'children': ['168', '181', '185']}; {'id': '168', 'type': 'if_statement', 'children': ['169', '175']}, {'id': '169', 'type': 'not_operator', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'begtime'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'list'}, {'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': 'begtime'}, {'id': '179', 'type': 'list', 'children': ['180'], 'value': '[begtime]'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'begtime'}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'begsam'}; {'id': '184', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '185', 'type': 'for_statement', 'children': ['186', '187', '188']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'one_begtime'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'begtime'}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'begsam'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': '_convert_time_to_sample'}, {'id': '197', 'type': 'argument_list', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'one_begtime'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '200', 'type': 'if_statement', 'children': ['201', '204']}, {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': 'is'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'endtime'}, {'id': '203', 'type': 'None', 'children': []}; {'id': '204', 'type': 'block', 'children': ['205', '218', '222']}, {'id': '205', 'type': 'if_statement', 'children': ['206', '212']}; {'id': '206', 'type': 'not_operator', 'children': ['207']}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '209', 'type': 'argument_list', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'endtime'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '212', 'type': 'block', 'children': ['213']}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'endtime'}; {'id': '216', 'type': 'list', 'children': ['217'], 'value': '[endtime]'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'endtime'}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'endsam'}, {'id': '221', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '222', 'type': 'for_statement', 'children': ['223', '224', '225']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'one_endtime'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'endtime'}, {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'endsam'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': '_convert_time_to_sample'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'one_endtime'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '237', 'type': 'if_statement', 'children': ['238', '244']}; {'id': '238', 'type': 'not_operator', 'children': ['239']}, {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '241', 'type': 'argument_list', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'begsam'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'list'}; {'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': 'begsam'}; {'id': '248', 'type': 'list', 'children': ['249'], 'value': '[begsam]'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'begsam'}; {'id': '250', 'type': 'if_statement', 'children': ['251', '257']}, {'id': '251', 'type': 'not_operator', 'children': ['252']}; {'id': '252', 'type': 'call', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '254', 'type': 'argument_list', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'endsam'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '257', 'type': 'block', 'children': ['258']}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}, {'id': '259', 'type': 'assignment', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'endsam'}, {'id': '261', 'type': 'list', 'children': ['262'], 'value': '[endsam]'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'endsam'}, {'id': '263', 'type': 'if_statement', 'children': ['264', '273']}; {'id': '264', 'type': 'comparison_operator', 'children': ['265', '269'], 'value': '!='}, {'id': '265', 'type': 'call', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'begsam'}, {'id': '269', 'type': 'call', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'endsam'}, {'id': '273', 'type': 'block', 'children': ['274']}; {'id': '274', 'type': 'raise_statement', 'children': ['275']}, {'id': '275', 'type': 'call', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'binary_operator', 'children': ['279', '280'], 'value': '+'}, {'id': '279', 'type': 'string', 'children': [], 'value': "'There should be the same number of start and '"}; {'id': '280', 'type': 'string', 'children': [], 'value': "'end point'"}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'n_trl'}; {'id': '284', 'type': 'call', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'begsam'}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}, {'id': '289', 'type': 'assignment', 'children': ['290', '295']}; {'id': '290', 'type': 'subscript', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '294', 'type': 'string', 'children': [], 'value': "'chan'"}, {'id': '295', 'type': 'call', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '297', 'type': 'argument_list', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'n_trl'}, {'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '301', 'type': 'string', 'children': [], 'value': "'O'"}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'assignment', 'children': ['304', '309']}; {'id': '304', 'type': 'subscript', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '308', 'type': 'string', 'children': [], 'value': "'time'"}, {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '311', 'type': 'argument_list', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'n_trl'}, {'id': '313', 'type': 'keyword_argument', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '315', 'type': 'string', 'children': [], 'value': "'O'"}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'assignment', 'children': ['318', '321']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '321', 'type': 'call', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '323', 'type': 'argument_list', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'n_trl'}, {'id': '325', 'type': 'keyword_argument', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '327', 'type': 'string', 'children': [], 'value': "'O'"}; {'id': '328', 'type': 'for_statement', 'children': ['329', '333', '342']}, {'id': '329', 'type': 'pattern_list', 'children': ['330', '331', '332']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'one_begsam'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'one_endsam'}, {'id': '333', 'type': 'call', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '335', 'type': 'argument_list', 'children': ['336', '340', '341']}; {'id': '336', 'type': 'call', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '338', 'type': 'argument_list', 'children': ['339']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'n_trl'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'begsam'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'endsam'}; {'id': '342', 'type': 'block', 'children': ['343', '349', '362', '373', '377', '410', '418', '434']}, {'id': '343', 'type': 'expression_statement', 'children': ['344']}; {'id': '344', 'type': 'assignment', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'dataset'}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'dataset'}, {'id': '349', 'type': 'expression_statement', 'children': ['350']}; {'id': '350', 'type': 'call', 'children': ['351', '354']}, {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'lg'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '354', 'type': 'argument_list', 'children': ['355']}, {'id': '355', 'type': 'call', 'children': ['356', '359']}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}, {'id': '357', 'type': 'string', 'children': [], 'value': "'begsam {0: 6}, endsam {1: 6}'"}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '359', 'type': 'argument_list', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'one_begsam'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'one_endsam'}; {'id': '362', 'type': 'expression_statement', 'children': ['363']}, {'id': '363', 'type': 'assignment', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'dat'}, {'id': '365', 'type': 'call', 'children': ['366', '369']}; {'id': '366', 'type': 'attribute', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'dataset'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'return_dat'}, {'id': '369', 'type': 'argument_list', 'children': ['370', '371', '372']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'idx_chan'}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'one_begsam'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'one_endsam'}, {'id': '373', 'type': 'expression_statement', 'children': ['374']}; {'id': '374', 'type': 'assignment', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'chan_in_dat'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '377', 'type': 'if_statement', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'add_ref'}, {'id': '379', 'type': 'block', 'children': ['380', '391', '403']}; {'id': '380', 'type': 'expression_statement', 'children': ['381']}, {'id': '381', 'type': 'assignment', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'zero_ref'}, {'id': '383', 'type': 'call', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'zeros'}, {'id': '385', 'type': 'argument_list', 'children': ['386']}; {'id': '386', 'type': 'tuple', 'children': ['387', '388']}, {'id': '387', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '388', 'type': 'binary_operator', 'children': ['389', '390'], 'value': '-'}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'one_endsam'}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'one_begsam'}, {'id': '391', 'type': 'expression_statement', 'children': ['392']}; {'id': '392', 'type': 'assignment', 'children': ['393', '394']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'dat'}; {'id': '394', 'type': 'call', 'children': ['395', '396']}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'concatenate'}; {'id': '396', 'type': 'argument_list', 'children': ['397', '400']}, {'id': '397', 'type': 'tuple', 'children': ['398', '399']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'dat'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'zero_ref'}; {'id': '400', 'type': 'keyword_argument', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '402', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'chan_in_dat'}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '408', 'type': 'argument_list', 'children': ['409']}, {'id': '409', 'type': 'string', 'children': [], 'value': "'_REF'"}; {'id': '410', 'type': 'expression_statement', 'children': ['411']}, {'id': '411', 'type': 'assignment', 'children': ['412', '417']}; {'id': '412', 'type': 'subscript', 'children': ['413', '416']}, {'id': '413', 'type': 'attribute', 'children': ['414', '415']}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '415', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'dat'}; {'id': '418', 'type': 'expression_statement', 'children': ['419']}, {'id': '419', 'type': 'assignment', 'children': ['420', '427']}; {'id': '420', 'type': 'subscript', 'children': ['421', '426']}, {'id': '421', 'type': 'subscript', 'children': ['422', '425']}; {'id': '422', 'type': 'attribute', 'children': ['423', '424']}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '425', 'type': 'string', 'children': [], 'value': "'chan'"}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '427', 'type': 'call', 'children': ['428', '429']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'asarray'}, {'id': '429', 'type': 'argument_list', 'children': ['430', '431']}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'chan_in_dat'}, {'id': '431', 'type': 'keyword_argument', 'children': ['432', '433']}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '433', 'type': 'string', 'children': [], 'value': "'U'"}; {'id': '434', 'type': 'expression_statement', 'children': ['435']}, {'id': '435', 'type': 'assignment', 'children': ['436', '443']}; {'id': '436', 'type': 'subscript', 'children': ['437', '442']}, {'id': '437', 'type': 'subscript', 'children': ['438', '441']}; {'id': '438', 'type': 'attribute', 'children': ['439', '440']}, {'id': '439', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '440', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '441', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '442', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '443', 'type': 'parenthesized_expression', 'children': ['444'], 'value': '()'}; {'id': '444', 'type': 'binary_operator', 'children': ['445', '450'], 'value': '/'}, {'id': '445', 'type': 'call', 'children': ['446', '447']}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'arange'}, {'id': '447', 'type': 'argument_list', 'children': ['448', '449']}; {'id': '448', 'type': 'identifier', 'children': [], 'value': 'one_begsam'}, {'id': '449', 'type': 'identifier', 'children': [], 'value': 'one_endsam'}; {'id': '450', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '451', 'type': 'return_statement', 'children': ['452']} | def read_data(self, chan=None, begtime=None, endtime=None, begsam=None,
endsam=None, s_freq=None):
data = ChanTime()
data.start_time = self.header['start_time']
data.s_freq = s_freq = s_freq if s_freq else self.header['s_freq']
if chan is None:
chan = self.header['chan_name']
if not (isinstance(chan, list) or isinstance(chan, tuple)):
raise TypeError('Parameter "chan" should be a list')
add_ref = False
if '_REF' in chan:
add_ref = True
chan[:] = [x for x in chan if x != '_REF']
idx_chan = [self.header['chan_name'].index(x) for x in chan]
if begtime is None and begsam is None:
begsam = 0
if endtime is None and endsam is None:
endsam = self.header['n_samples']
if begtime is not None:
if not isinstance(begtime, list):
begtime = [begtime]
begsam = []
for one_begtime in begtime:
begsam.append(_convert_time_to_sample(one_begtime, self))
if endtime is not None:
if not isinstance(endtime, list):
endtime = [endtime]
endsam = []
for one_endtime in endtime:
endsam.append(_convert_time_to_sample(one_endtime, self))
if not isinstance(begsam, list):
begsam = [begsam]
if not isinstance(endsam, list):
endsam = [endsam]
if len(begsam) != len(endsam):
raise ValueError('There should be the same number of start and ' +
'end point')
n_trl = len(begsam)
data.axis['chan'] = empty(n_trl, dtype='O')
data.axis['time'] = empty(n_trl, dtype='O')
data.data = empty(n_trl, dtype='O')
for i, one_begsam, one_endsam in zip(range(n_trl), begsam, endsam):
dataset = self.dataset
lg.debug('begsam {0: 6}, endsam {1: 6}'.format(one_begsam,
one_endsam))
dat = dataset.return_dat(idx_chan, one_begsam, one_endsam)
chan_in_dat = chan
if add_ref:
zero_ref = zeros((1, one_endsam - one_begsam))
dat = concatenate((dat, zero_ref), axis=0)
chan_in_dat.append('_REF')
data.data[i] = dat
data.axis['chan'][i] = asarray(chan_in_dat, dtype='U')
data.axis['time'][i] = (arange(one_begsam, one_endsam) / s_freq)
return data |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'export_freq_band'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'xfreq'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'bands'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '7', 'type': 'block', 'children': ['8', '21', '34', '54', '62', '104', '145', '152']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'heading_row_1'}, {'id': '11', 'type': 'list', 'children': ['12', '13', '14', '15', '16', '17', '18', '19', '20'], 'value': "['Segment index',\n 'Start time',\n 'End time',\n 'Duration',\n 'Stitches',\n 'Stage',\n 'Cycle',\n 'Event type',\n 'Channel',\n ]"}; {'id': '12', 'type': 'string', 'children': [], 'value': "'Segment index'"}, {'id': '13', 'type': 'string', 'children': [], 'value': "'Start time'"}; {'id': '14', 'type': 'string', 'children': [], 'value': "'End time'"}, {'id': '15', 'type': 'string', 'children': [], 'value': "'Duration'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'Stitches'"}, {'id': '17', 'type': 'string', 'children': [], 'value': "'Stage'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'Cycle'"}, {'id': '19', 'type': 'string', 'children': [], 'value': "'Event type'"}; {'id': '20', 'type': 'string', 'children': [], 'value': "'Channel'"}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'spacer'}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '27'], 'value': '*'}, {'id': '25', 'type': 'list', 'children': ['26'], 'value': "['']"}; {'id': '26', 'type': 'string', 'children': [], 'value': "''"}, {'id': '27', 'type': 'parenthesized_expression', 'children': ['28'], 'value': '()'}; {'id': '28', 'type': 'binary_operator', 'children': ['29', '33'], 'value': '-'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'heading_row_1'}, {'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': 'band_hdr'}, {'id': '37', 'type': 'list_comprehension', 'children': ['38', '49']}; {'id': '38', 'type': 'binary_operator', 'children': ['39', '45'], 'value': '+'}, {'id': '39', 'type': 'binary_operator', 'children': ['40', '44'], 'value': '+'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'b1'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'b2'}, {'id': '49', 'type': 'for_in_clause', 'children': ['50', '53']}; {'id': '50', 'type': 'pattern_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'b1'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'b2'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'bands'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'xband'}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'xfreq'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'for_statement', 'children': ['63', '64', '65']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'xband'}, {'id': '65', 'type': 'block', 'children': ['66', '70', '98']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'bandlist'}, {'id': '69', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '70', 'type': 'for_statement', 'children': ['71', '74', '78']}, {'id': '71', 'type': 'pattern_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'bands'}; {'id': '78', 'type': 'block', 'children': ['79', '91']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '84']}, {'id': '81', 'type': 'pattern_list', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'pwr'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'band_power'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '90']}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '89', 'type': 'string', 'children': [], 'value': "'data'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'bandlist'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'pwr'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '103']}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'band'"}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'bandlist'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'as_matrix'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'asarray'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'list_comprehension', 'children': ['111', '130', '131', '134']}, {'id': '111', 'type': 'list_comprehension', 'children': ['112', '119']}; {'id': '112', 'type': 'subscript', 'children': ['113', '118']}, {'id': '113', 'type': 'subscript', 'children': ['114', '117']}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'band'"}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '119', 'type': 'for_in_clause', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '129', 'type': 'string', 'children': [], 'value': "'band'"}; {'id': '130', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '131', 'type': 'for_in_clause', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'xband'}; {'id': '134', 'type': 'for_in_clause', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '136', 'type': 'call', 'children': ['137', '144']}, {'id': '137', 'type': 'attribute', 'children': ['138', '143']}; {'id': '138', 'type': 'subscript', 'children': ['139', '142']}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'band'"}; {'id': '142', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '144', 'type': 'argument_list', 'children': []}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'get_descriptives'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'as_matrix'}; {'id': '152', 'type': 'with_statement', 'children': ['153', '166']}, {'id': '153', 'type': 'with_clause', 'children': ['154']}; {'id': '154', 'type': 'with_item', 'children': ['155']}, {'id': '155', 'type': 'as_pattern', 'children': ['156', '164']}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '160', '161']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'w'"}, {'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'newline'}, {'id': '163', 'type': 'string', 'children': [], 'value': "''"}; {'id': '164', 'type': 'as_pattern_target', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '166', 'type': 'block', 'children': ['167', '179', '186', '199', '208', '225', '242', '259', '276', '280']}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'lg'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'binary_operator', 'children': ['174', '175'], 'value': '+'}; {'id': '174', 'type': 'string', 'children': [], 'value': "'Writing to '"}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'csv_file'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'writer'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'csv_file'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'writerow'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'list', 'children': ['193'], 'value': "['Wonambi v{}'.format(__version__)]"}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'string', 'children': [], 'value': "'Wonambi v{}'"}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': '__version__'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'csv_file'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'writerow'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '+'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'heading_row_1'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'band_hdr'}; {'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': 'csv_file'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'writerow'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'binary_operator', 'children': ['215', '219'], 'value': '+'}, {'id': '215', 'type': 'binary_operator', 'children': ['216', '218'], 'value': '+'}; {'id': '216', 'type': 'list', 'children': ['217'], 'value': "['Mean']"}, {'id': '217', 'type': 'string', 'children': [], 'value': "'Mean'"}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'spacer'}, {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '224', 'type': 'string', 'children': [], 'value': "'mean'"}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'call', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'csv_file'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'writerow'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}, {'id': '231', 'type': 'binary_operator', 'children': ['232', '236'], 'value': '+'}; {'id': '232', 'type': 'binary_operator', 'children': ['233', '235'], 'value': '+'}, {'id': '233', 'type': 'list', 'children': ['234'], 'value': "['SD']"}; {'id': '234', 'type': 'string', 'children': [], 'value': "'SD'"}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'spacer'}; {'id': '236', 'type': 'call', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'subscript', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '241', 'type': 'string', 'children': [], 'value': "'sd'"}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'call', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'csv_file'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'writerow'}, {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'binary_operator', 'children': ['249', '253'], 'value': '+'}, {'id': '249', 'type': 'binary_operator', 'children': ['250', '252'], 'value': '+'}; {'id': '250', 'type': 'list', 'children': ['251'], 'value': "['Mean of ln']"}, {'id': '251', 'type': 'string', 'children': [], 'value': "'Mean of ln'"}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'spacer'}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'subscript', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '258', 'type': 'string', 'children': [], 'value': "'mean_log'"}, {'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': 'csv_file'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'writerow'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}, {'id': '265', 'type': 'binary_operator', 'children': ['266', '270'], 'value': '+'}; {'id': '266', 'type': 'binary_operator', 'children': ['267', '269'], 'value': '+'}, {'id': '267', 'type': 'list', 'children': ['268'], 'value': "['SD of ln']"}; {'id': '268', 'type': 'string', 'children': [], 'value': "'SD of ln'"}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'spacer'}; {'id': '270', 'type': 'call', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'subscript', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '275', 'type': 'string', 'children': [], 'value': "'sd_log'"}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '279', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '280', 'type': 'for_statement', 'children': ['281', '282', '283']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'xband'}, {'id': '283', 'type': 'block', 'children': ['284']}; {'id': '284', 'type': 'for_statement', 'children': ['285', '286', '295']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '286', 'type': 'call', 'children': ['287', '294']}, {'id': '287', 'type': 'attribute', 'children': ['288', '293']}; {'id': '288', 'type': 'subscript', 'children': ['289', '292']}, {'id': '289', 'type': 'subscript', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '291', 'type': 'string', 'children': [], 'value': "'band'"}; {'id': '292', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '294', 'type': 'argument_list', 'children': []}, {'id': '295', 'type': 'block', 'children': ['296', '300', '304', '319', '344']}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}, {'id': '297', 'type': 'augmented_assignment', 'children': ['298', '299'], 'value': '+='}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '299', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'cyc'}, {'id': '303', 'type': 'None', 'children': []}; {'id': '304', 'type': 'if_statement', 'children': ['305', '310']}, {'id': '305', 'type': 'comparison_operator', 'children': ['306', '309'], 'value': 'is'}; {'id': '306', 'type': 'subscript', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '308', 'type': 'string', 'children': [], 'value': "'cycle'"}, {'id': '309', 'type': 'None', 'children': []}; {'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': 'cyc'}; {'id': '314', 'type': 'subscript', 'children': ['315', '318']}, {'id': '315', 'type': 'subscript', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '317', 'type': 'string', 'children': [], 'value': "'cycle'"}; {'id': '318', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '319', 'type': 'expression_statement', 'children': ['320']}; {'id': '320', 'type': 'assignment', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'data_row'}; {'id': '322', 'type': 'call', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '324', 'type': 'argument_list', 'children': ['325']}, {'id': '325', 'type': 'list_comprehension', 'children': ['326', '333']}; {'id': '326', 'type': 'subscript', 'children': ['327', '332']}, {'id': '327', 'type': 'subscript', 'children': ['328', '331']}; {'id': '328', 'type': 'subscript', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '330', 'type': 'string', 'children': [], 'value': "'band'"}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '333', 'type': 'for_in_clause', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '335', 'type': 'call', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '337', 'type': 'argument_list', 'children': ['338']}; {'id': '338', 'type': 'call', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '340', 'type': 'argument_list', 'children': ['341']}, {'id': '341', 'type': 'subscript', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '343', 'type': 'string', 'children': [], 'value': "'band'"}; {'id': '344', 'type': 'expression_statement', 'children': ['345']}, {'id': '345', 'type': 'call', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'csv_file'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'writerow'}, {'id': '349', 'type': 'argument_list', 'children': ['350']}; {'id': '350', 'type': 'binary_operator', 'children': ['351', '373'], 'value': '+'}, {'id': '351', 'type': 'list', 'children': ['352', '353', '356', '359', '362', '365', '368', '369', '372'], 'value': "[idx,\n seg['start'],\n seg['end'],\n seg['duration'],\n seg['n_stitch'],\n seg['stage'],\n cyc,\n seg['name'],\n chan,\n ]"}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '353', 'type': 'subscript', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '355', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '356', 'type': 'subscript', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '358', 'type': 'string', 'children': [], 'value': "'end'"}, {'id': '359', 'type': 'subscript', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '361', 'type': 'string', 'children': [], 'value': "'duration'"}; {'id': '362', 'type': 'subscript', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '364', 'type': 'string', 'children': [], 'value': "'n_stitch'"}, {'id': '365', 'type': 'subscript', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '367', 'type': 'string', 'children': [], 'value': "'stage'"}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'cyc'}, {'id': '369', 'type': 'subscript', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '371', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'data_row'} | def export_freq_band(xfreq, bands, filename):
heading_row_1 = ['Segment index',
'Start time',
'End time',
'Duration',
'Stitches',
'Stage',
'Cycle',
'Event type',
'Channel',
]
spacer = [''] * (len(heading_row_1) - 1)
band_hdr = [str(b1) + '-' + str(b2) for b1, b2 in bands]
xband = xfreq.copy()
for seg in xband:
bandlist = []
for i, b in enumerate(bands):
pwr, _ = band_power(seg['data'], b)
bandlist.append(pwr)
seg['band'] = bandlist
as_matrix = asarray([
[x['band'][y][chan] for y in range(len(x['band']))] \
for x in xband for chan in x['band'][0].keys()])
desc = get_descriptives(as_matrix)
with open(filename, 'w', newline='') as f:
lg.info('Writing to ' + str(filename))
csv_file = writer(f)
csv_file.writerow(['Wonambi v{}'.format(__version__)])
csv_file.writerow(heading_row_1 + band_hdr)
csv_file.writerow(['Mean'] + spacer + list(desc['mean']))
csv_file.writerow(['SD'] + spacer + list(desc['sd']))
csv_file.writerow(['Mean of ln'] + spacer + list(desc['mean_log']))
csv_file.writerow(['SD of ln'] + spacer + list(desc['sd_log']))
idx = 0
for seg in xband:
for chan in seg['band'][0].keys():
idx += 1
cyc = None
if seg['cycle'] is not None:
cyc = seg['cycle'][2]
data_row = list(
[seg['band'][x][chan] for x in range(
len(seg['band']))])
csv_file.writerow([idx,
seg['start'],
seg['end'],
seg['duration'],
seg['n_stitch'],
seg['stage'],
cyc,
seg['name'],
chan,
] + data_row) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_cycles'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '17', '23', '44', '65', '69', '78', '96', '180', '184', '213']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'cycles'}, {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'rater'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'cycles'"}, {'id': '17', 'type': 'if_statement', 'children': ['18', '20']}; {'id': '18', 'type': 'not_operator', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'cycles'}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'starts'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'list_comprehension', 'children': ['30', '36']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'mrkr'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'mrkr'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'cycles'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'findall'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'string', 'children': [], 'value': "'cyc_start'"}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ends'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'list_comprehension', 'children': ['51', '57']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'mrkr'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'mrkr'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'cycles'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'findall'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'cyc_end'"}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'cyc_list'}; {'id': '68', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '75']}; {'id': '70', 'type': 'boolean_operator', 'children': ['71', '73'], 'value': 'or'}, {'id': '71', 'type': 'not_operator', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'starts'}, {'id': '73', 'type': 'not_operator', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ends'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'return_statement', 'children': ['77']}, {'id': '77', 'type': 'None', 'children': []}; {'id': '78', 'type': 'if_statement', 'children': ['79', '90']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '81', 'type': 'generator_expression', 'children': ['82', '87']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '<'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'starts'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '87', 'type': 'for_in_clause', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ends'}; {'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': "'First cycle has no start.'"}; {'id': '96', 'type': 'for_statement', 'children': ['97', '100', '112']}, {'id': '97', 'type': 'tuple_pattern', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'this_start'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'next_start'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'starts'}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '110'], 'value': '+'}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'starts'}, {'id': '107', 'type': 'slice', 'children': ['108', '109']}; {'id': '108', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '109', 'type': 'colon', 'children': []}; {'id': '110', 'type': 'list', 'children': ['111'], 'value': '[inf]'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'inf'}; {'id': '112', 'type': 'block', 'children': ['113', '127', '142', '161', '173']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'end_between_starts'}; {'id': '116', 'type': 'list_comprehension', 'children': ['117', '118', '121', '122']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '118', 'type': 'for_in_clause', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'ends'}, {'id': '121', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '122', 'type': 'if_clause', 'children': ['123']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '125', '126'], 'value': '<'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'this_start'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'next_start'}, {'id': '127', 'type': 'if_statement', 'children': ['128', '134']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '133'], 'value': '>'}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'end_between_starts'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'raise_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'concatenated_string', 'children': ['140', '141']}; {'id': '140', 'type': 'string', 'children': [], 'value': "'Found more than one cycle end for same '"}, {'id': '141', 'type': 'string', 'children': [], 'value': "'cycle'"}; {'id': '142', 'type': 'if_statement', 'children': ['143', '144', '153']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'end_between_starts'}; {'id': '144', 'type': 'block', 'children': ['145']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'one_cycle'}; {'id': '148', 'type': 'tuple', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'this_start'}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'end_between_starts'}; {'id': '152', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '153', 'type': 'else_clause', 'children': ['154']}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'one_cycle'}; {'id': '158', 'type': 'tuple', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'this_start'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'next_start'}, {'id': '161', 'type': 'if_statement', 'children': ['162', '167']}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '166'], 'value': '=='}, {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'one_cycle'}, {'id': '165', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'inf'}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'raise_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'string', 'children': [], 'value': "'Last cycle has no end.'"}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'cyc_list'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'one_cycle'}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '183', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '184', 'type': 'for_statement', 'children': ['185', '188', '192']}, {'id': '185', 'type': 'pattern_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'cyc_list'}; {'id': '192', 'type': 'block', 'children': ['193', '206']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'cyc'}; {'id': '196', 'type': 'expression_list', 'children': ['197', '200', '203']}, {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '199', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '202', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '203', 'type': 'binary_operator', 'children': ['204', '205'], 'value': '+'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '205', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'cyc'}, {'id': '213', 'type': 'return_statement', 'children': ['214']} | def get_cycles(self):
cycles = self.rater.find('cycles')
if not cycles:
return None
starts = sorted(
[float(mrkr.text) for mrkr in cycles.findall('cyc_start')])
ends = sorted(
[float(mrkr.text) for mrkr in cycles.findall('cyc_end')])
cyc_list = []
if not starts or not ends:
return None
if all(i < starts[0] for i in ends):
raise ValueError('First cycle has no start.')
for (this_start, next_start) in zip(starts, starts[1:] + [inf]):
end_between_starts = [end for end in ends \
if this_start < end <= next_start]
if len(end_between_starts) > 1:
raise ValueError('Found more than one cycle end for same '
'cycle')
if end_between_starts:
one_cycle = (this_start, end_between_starts[0])
else:
one_cycle = (this_start, next_start)
if one_cycle[1] == inf:
raise ValueError('Last cycle has no end.')
cyc_list.append(one_cycle)
output = []
for i, j in enumerate(cyc_list):
cyc = j[0], j[1], i + 1
output.append(cyc)
return output |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_read_erd'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'erd_file'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'begsam'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'endsam'}, {'id': '7', 'type': 'block', 'children': ['8', '15', '21', '27', '34', '44', '61', '74', '80', '89', '96', '108', '114', '126', '162', '278', '331', '338']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'hdr'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_read_hdr_file'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'erd_file'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'n_allchan'}; {'id': '18', 'type': 'subscript', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'hdr'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'num_channels'"}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'shorted'}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'hdr'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'shorted'"}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'n_shorted'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'shorted'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38']}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '>'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'n_shorted'}, {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'raise_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'string', 'children': [], 'value': "'shorted channels not tested yet'"}; {'id': '44', 'type': 'if_statement', 'children': ['45', '51']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': 'in'}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'hdr'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'file_schema'"}, {'id': '49', 'type': 'tuple', 'children': ['50']}; {'id': '50', 'type': 'integer', 'children': [], 'value': '7'}, {'id': '51', 'type': 'block', 'children': ['52', '56']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'abs_delta'}, {'id': '55', 'type': 'string', 'children': [], 'value': "b'\\x80'"}; {'id': '56', 'type': 'raise_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'string', 'children': [], 'value': "'schema 7 not tested yet'"}, {'id': '61', 'type': 'if_statement', 'children': ['62', '69']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '66'], 'value': 'in'}, {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'hdr'}, {'id': '65', 'type': 'string', 'children': [], 'value': "'file_schema'"}; {'id': '66', 'type': 'tuple', 'children': ['67', '68']}, {'id': '67', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '9'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'abs_delta'}, {'id': '73', 'type': 'string', 'children': [], 'value': "b'\\xff\\xff'"}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'n_smp'}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '-'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'endsam'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'begsam'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'tuple', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'n_allchan'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'n_smp'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'fill'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'NaN'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'etc'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': '_read_etc'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'erd_file'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'with_suffix'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'string', 'children': [], 'value': "'.etc'"}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'all_beg'}, {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'etc'}, {'id': '113', 'type': 'string', 'children': [], 'value': "'samplestamp'"}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'all_end'}, {'id': '117', 'type': 'binary_operator', 'children': ['118', '125'], 'value': '-'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '122'], 'value': '+'}, {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'etc'}, {'id': '121', 'type': 'string', 'children': [], 'value': "'samplestamp'"}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'etc'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'sample_span'"}, {'id': '125', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '126', 'type': 'try_statement', 'children': ['127', '157']}, {'id': '127', 'type': 'block', 'children': ['128', '142']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'begrec'}, {'id': '131', 'type': 'subscript', 'children': ['132', '141']}; {'id': '132', 'type': 'subscript', 'children': ['133', '140']}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'where'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'parenthesized_expression', 'children': ['137'], 'value': '()'}, {'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': '>='}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'all_end'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'begsam'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '141', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'endrec'}, {'id': '145', 'type': 'subscript', 'children': ['146', '155']}; {'id': '146', 'type': 'subscript', 'children': ['147', '154']}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'where'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'parenthesized_expression', 'children': ['151'], 'value': '()'}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': '<'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'all_beg'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'endsam'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '155', 'type': 'unary_operator', 'children': ['156'], 'value': '-'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '157', 'type': 'except_clause', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'IndexError'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'return_statement', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '162', 'type': 'with_statement', 'children': ['163', '174']}, {'id': '163', 'type': 'with_clause', 'children': ['164']}; {'id': '164', 'type': 'with_item', 'children': ['165']}, {'id': '165', 'type': 'as_pattern', 'children': ['166', '172']}; {'id': '166', 'type': 'call', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'erd_file'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '172', 'type': 'as_pattern_target', 'children': ['173']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '174', 'type': 'block', 'children': ['175']}, {'id': '175', 'type': 'for_statement', 'children': ['176', '177', '184']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '179', 'type': 'argument_list', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'begrec'}, {'id': '181', 'type': 'binary_operator', 'children': ['182', '183'], 'value': '+'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'endrec'}, {'id': '183', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '184', 'type': 'block', 'children': ['185', '193', '201', '209', '225', '235', '245', '260']}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'begpos_rec'}; {'id': '188', 'type': 'binary_operator', 'children': ['189', '190'], 'value': '-'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'begsam'}; {'id': '190', 'type': 'subscript', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'all_beg'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'endpos_rec'}; {'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '-'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'endsam'}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'all_beg'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'begpos_rec'}; {'id': '204', 'type': 'call', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '206', 'type': 'argument_list', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'begpos_rec'}; {'id': '208', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'endpos_rec'}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'endpos_rec'}; {'id': '216', 'type': 'binary_operator', 'children': ['217', '224'], 'value': '+'}, {'id': '217', 'type': 'binary_operator', 'children': ['218', '221'], 'value': '-'}; {'id': '218', 'type': 'subscript', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'all_end'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '221', 'type': 'subscript', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'all_beg'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'd1'}; {'id': '228', 'type': 'binary_operator', 'children': ['229', '234'], 'value': '-'}, {'id': '229', 'type': 'binary_operator', 'children': ['230', '231'], 'value': '+'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'begpos_rec'}, {'id': '231', 'type': 'subscript', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'all_beg'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'begsam'}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'd2'}; {'id': '238', 'type': 'binary_operator', 'children': ['239', '244'], 'value': '-'}, {'id': '239', 'type': 'binary_operator', 'children': ['240', '241'], 'value': '+'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'endpos_rec'}, {'id': '241', 'type': 'subscript', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'all_beg'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'begsam'}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'dat'}; {'id': '248', 'type': 'call', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': '_read_packet'}; {'id': '250', 'type': 'argument_list', 'children': ['251', '252', '257', '258', '259']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '252', 'type': 'subscript', 'children': ['253', '256']}, {'id': '253', 'type': 'subscript', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'etc'}, {'id': '255', 'type': 'string', 'children': [], 'value': "'offset'"}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'rec'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'endpos_rec'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'n_allchan'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'abs_delta'}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'assignment', 'children': ['262', '270']}; {'id': '262', 'type': 'subscript', 'children': ['263', '264', '266']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '264', 'type': 'slice', 'children': ['265']}, {'id': '265', 'type': 'colon', 'children': []}; {'id': '266', 'type': 'slice', 'children': ['267', '268', '269']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'd1'}; {'id': '268', 'type': 'colon', 'children': []}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'd2'}; {'id': '270', 'type': 'subscript', 'children': ['271', '272', '274']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'dat'}; {'id': '272', 'type': 'slice', 'children': ['273']}, {'id': '273', 'type': 'colon', 'children': []}; {'id': '274', 'type': 'slice', 'children': ['275', '276', '277']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'begpos_rec'}; {'id': '276', 'type': 'colon', 'children': []}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'endpos_rec'}; {'id': '278', 'type': 'if_statement', 'children': ['279', '282', '325']}, {'id': '279', 'type': 'comparison_operator', 'children': ['280', '281'], 'value': '>'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'n_shorted'}, {'id': '281', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '282', 'type': 'block', 'children': ['283', '301', '310', '317']}, {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'full_channels'}; {'id': '286', 'type': 'subscript', 'children': ['287', '300']}, {'id': '287', 'type': 'call', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'where'}, {'id': '289', 'type': 'argument_list', 'children': ['290']}; {'id': '290', 'type': 'call', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}, {'id': '293', 'type': 'list_comprehension', 'children': ['294', '297']}; {'id': '294', 'type': 'comparison_operator', 'children': ['295', '296'], 'value': '=='}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '296', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '297', 'type': 'for_in_clause', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'shorted'}; {'id': '300', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'assignment', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '304', 'type': 'call', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '306', 'type': 'argument_list', 'children': ['307']}, {'id': '307', 'type': 'tuple', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'n_allchan'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'n_smp'}; {'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': 'output'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'fill'}, {'id': '315', 'type': 'argument_list', 'children': ['316']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'NaN'}, {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'assignment', 'children': ['319', '324']}, {'id': '319', 'type': 'subscript', 'children': ['320', '321', '322']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'full_channels'}; {'id': '322', 'type': 'slice', 'children': ['323']}, {'id': '323', 'type': 'colon', 'children': []}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '325', 'type': 'else_clause', 'children': ['326']}; {'id': '326', 'type': 'block', 'children': ['327']}, {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'assignment', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '331', 'type': 'expression_statement', 'children': ['332']}; {'id': '332', 'type': 'assignment', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'factor'}; {'id': '334', 'type': 'call', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': '_calculate_conversion'}; {'id': '336', 'type': 'argument_list', 'children': ['337']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'hdr'}; {'id': '338', 'type': 'return_statement', 'children': ['339']}, {'id': '339', 'type': 'binary_operator', 'children': ['340', '345'], 'value': '*'}; {'id': '340', 'type': 'call', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'expand_dims'}; {'id': '342', 'type': 'argument_list', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'factor'}; {'id': '344', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'output'} | def _read_erd(erd_file, begsam, endsam):
hdr = _read_hdr_file(erd_file)
n_allchan = hdr['num_channels']
shorted = hdr['shorted']
n_shorted = sum(shorted)
if n_shorted > 0:
raise NotImplementedError('shorted channels not tested yet')
if hdr['file_schema'] in (7,):
abs_delta = b'\x80'
raise NotImplementedError('schema 7 not tested yet')
if hdr['file_schema'] in (8, 9):
abs_delta = b'\xff\xff'
n_smp = endsam - begsam
data = empty((n_allchan, n_smp))
data.fill(NaN)
etc = _read_etc(erd_file.with_suffix('.etc'))
all_beg = etc['samplestamp']
all_end = etc['samplestamp'] + etc['sample_span'] - 1
try:
begrec = where((all_end >= begsam))[0][0]
endrec = where((all_beg < endsam))[0][-1]
except IndexError:
return data
with erd_file.open('rb') as f:
for rec in range(begrec, endrec + 1):
begpos_rec = begsam - all_beg[rec]
endpos_rec = endsam - all_beg[rec]
begpos_rec = max(begpos_rec, 0)
endpos_rec = min(endpos_rec, all_end[rec] - all_beg[rec] + 1)
d1 = begpos_rec + all_beg[rec] - begsam
d2 = endpos_rec + all_beg[rec] - begsam
dat = _read_packet(f, etc['offset'][rec], endpos_rec, n_allchan,
abs_delta)
data[:, d1:d2] = dat[:, begpos_rec:endpos_rec]
if n_shorted > 0:
full_channels = where(asarray([x == 0 for x in shorted]))[0]
output = empty((n_allchan, n_smp))
output.fill(NaN)
output[full_channels, :] = data
else:
output = data
factor = _calculate_conversion(hdr)
return expand_dims(factor, 1) * output |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'return_markers'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '17', '36', '318']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ent_file'}, {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '_filename'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'with_suffix'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'.ent'"}, {'id': '17', 'type': 'if_statement', 'children': ['18', '24']}; {'id': '18', 'type': 'not_operator', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ent_file'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ent_file'}; {'id': '28', 'type': 'call', 'children': ['29', '34']}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_filename'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'with_suffix'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'.ent.old'"}; {'id': '36', 'type': 'try_statement', 'children': ['37', '45', '54']}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ent_notes'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_read_ent'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ent_file'}, {'id': '45', 'type': 'except_clause', 'children': ['46', '49']}; {'id': '46', 'type': 'tuple', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'FileNotFoundError'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'PermissionError'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'markers'}, {'id': '53', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '54', 'type': 'else_clause', 'children': ['55']}, {'id': '55', 'type': 'block', 'children': ['56', '60', '102', '112', '116', '120', '124', '128', '273', '277']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'allnote'}, {'id': '59', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '60', 'type': 'for_statement', 'children': ['61', '62', '63']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ent_notes'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'try_statement', 'children': ['65', '83']}, {'id': '65', 'type': 'block', 'children': ['66', '74']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '73']}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}, {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'allnote'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'value'"}, {'id': '83', 'type': 'except_clause', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'lg'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '98']}, {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'concatenated_string', 'children': ['95', '96']}, {'id': '95', 'type': 'string', 'children': [], 'value': "'Note of length {} was not '"}; {'id': '96', 'type': 'string', 'children': [], 'value': "'converted to dict'"}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'length'"}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '105', 'type': 'subscript', 'children': ['106', '111']}; {'id': '106', 'type': 'subscript', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': '_hdr'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'erd'"}, {'id': '111', 'type': 'string', 'children': [], 'value': "'sample_freq'"}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'pcname'}, {'id': '115', 'type': 'string', 'children': [], 'value': "'0CFEBE72-DA20-4b3a-A8AC-CDD41BFE2F0D'"}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'note_time'}, {'id': '119', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'note_name'}, {'id': '123', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'note_note'}, {'id': '127', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '128', 'type': 'for_statement', 'children': ['129', '130', '131']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'allnote'}, {'id': '131', 'type': 'block', 'children': ['132', '140', '147', '159', '169', '173', '183', '193', '203', '215', '253', '264']}; {'id': '132', 'type': 'if_statement', 'children': ['133', '138']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '137'], 'value': '=='}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '136', 'type': 'string', 'children': [], 'value': "'Text'"}, {'id': '137', 'type': 'string', 'children': [], 'value': "'Analyzed Data Note'"}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'continue_statement', 'children': []}; {'id': '140', 'type': 'if_statement', 'children': ['141', '145']}, {'id': '141', 'type': 'not_operator', 'children': ['142']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'Text'"}, {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'continue_statement', 'children': []}, {'id': '147', 'type': 'if_statement', 'children': ['148', '157']}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'not'}, {'id': '149', 'type': 'string', 'children': [], 'value': "'User'"}; {'id': '150', 'type': 'call', 'children': ['151', '156']}, {'id': '151', 'type': 'attribute', 'children': ['152', '155']}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '154', 'type': 'string', 'children': [], 'value': "'Data'"}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '156', 'type': 'argument_list', 'children': []}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'continue_statement', 'children': []}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'user1'}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '168'], 'value': '=='}, {'id': '163', 'type': 'subscript', 'children': ['164', '167']}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '166', 'type': 'string', 'children': [], 'value': "'Data'"}, {'id': '167', 'type': 'string', 'children': [], 'value': "'User'"}; {'id': '168', 'type': 'string', 'children': [], 'value': "'Persyst'"}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'user2'}; {'id': '172', 'type': 'False', 'children': []}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'user3'}; {'id': '176', 'type': 'comparison_operator', 'children': ['177', '182'], 'value': '=='}, {'id': '177', 'type': 'subscript', 'children': ['178', '181']}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '180', 'type': 'string', 'children': [], 'value': "'Data'"}, {'id': '181', 'type': 'string', 'children': [], 'value': "'User'"}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'pcname'}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'user4'}; {'id': '186', 'type': 'comparison_operator', 'children': ['187', '192'], 'value': '=='}, {'id': '187', 'type': 'subscript', 'children': ['188', '191']}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '190', 'type': 'string', 'children': [], 'value': "'Data'"}, {'id': '191', 'type': 'string', 'children': [], 'value': "'User'"}; {'id': '192', 'type': 'string', 'children': [], 'value': "'XLSpike - Intracranial'"}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'user5'}; {'id': '196', 'type': 'comparison_operator', 'children': ['197', '202'], 'value': '=='}, {'id': '197', 'type': 'subscript', 'children': ['198', '201']}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '200', 'type': 'string', 'children': [], 'value': "'Data'"}, {'id': '201', 'type': 'string', 'children': [], 'value': "'User'"}; {'id': '202', 'type': 'string', 'children': [], 'value': "'XLEvent - Intracranial'"}, {'id': '203', 'type': 'if_statement', 'children': ['204', '213']}; {'id': '204', 'type': 'boolean_operator', 'children': ['205', '212'], 'value': 'or'}, {'id': '205', 'type': 'boolean_operator', 'children': ['206', '211'], 'value': 'or'}; {'id': '206', 'type': 'boolean_operator', 'children': ['207', '210'], 'value': 'or'}, {'id': '207', 'type': 'boolean_operator', 'children': ['208', '209'], 'value': 'or'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'user1'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'user2'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'user3'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'user4'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'user5'}, {'id': '213', 'type': 'block', 'children': ['214']}; {'id': '214', 'type': 'continue_statement', 'children': []}, {'id': '215', 'type': 'if_statement', 'children': ['216', '226', '234']}; {'id': '216', 'type': 'comparison_operator', 'children': ['217', '225'], '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': 'subscript', 'children': ['221', '224']}, {'id': '221', 'type': 'subscript', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '223', 'type': 'string', 'children': [], 'value': "'Data'"}; {'id': '224', 'type': 'string', 'children': [], 'value': "'User'"}, {'id': '225', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '226', 'type': 'block', 'children': ['227']}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'note_name'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'string', 'children': [], 'value': "'-unknown-'"}; {'id': '234', 'type': 'else_clause', 'children': ['235']}, {'id': '235', 'type': 'block', 'children': ['236']}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'note_name'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'subscript', 'children': ['243', '252']}, {'id': '243', 'type': 'call', 'children': ['244', '251']}; {'id': '244', 'type': 'attribute', 'children': ['245', '250']}, {'id': '245', 'type': 'subscript', 'children': ['246', '249']}; {'id': '246', 'type': 'subscript', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '248', 'type': 'string', 'children': [], 'value': "'Data'"}, {'id': '249', 'type': 'string', 'children': [], 'value': "'User'"}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '251', 'type': 'argument_list', 'children': []}; {'id': '252', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'call', 'children': ['255', '258']}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'note_time'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}, {'id': '259', 'type': 'binary_operator', 'children': ['260', '263'], 'value': '/'}; {'id': '260', 'type': 'subscript', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '262', 'type': 'string', 'children': [], 'value': "'Stamp'"}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 's_freq'}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'note_note'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'subscript', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '272', 'type': 'string', 'children': [], 'value': "'Text'"}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'markers'}; {'id': '276', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '277', 'type': 'for_statement', 'children': ['278', '282', '288']}; {'id': '278', 'type': 'pattern_list', 'children': ['279', '280', '281']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'note'}; {'id': '282', 'type': 'call', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '286', '287']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'note_time'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'note_name'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'note_note'}; {'id': '288', 'type': 'block', 'children': ['289', '311']}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '292', 'type': 'dictionary', 'children': ['293', '302', '305', '308']}, {'id': '293', 'type': 'pair', 'children': ['294', '295']}; {'id': '294', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '295', 'type': 'binary_operator', 'children': ['296', '301'], 'value': '+'}; {'id': '296', 'type': 'binary_operator', 'children': ['297', '300'], 'value': '+'}, {'id': '297', 'type': 'binary_operator', 'children': ['298', '299'], 'value': '+'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'note'}, {'id': '299', 'type': 'string', 'children': [], 'value': "' ('"}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '301', 'type': 'string', 'children': [], 'value': "')'"}; {'id': '302', 'type': 'pair', 'children': ['303', '304']}, {'id': '303', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '305', 'type': 'pair', 'children': ['306', '307']}; {'id': '306', 'type': 'string', 'children': [], 'value': "'end'"}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '308', 'type': 'pair', 'children': ['309', '310']}, {'id': '309', 'type': 'string', 'children': [], 'value': "'chan'"}; {'id': '310', 'type': 'None', 'children': []}, {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'call', 'children': ['313', '316']}, {'id': '313', 'type': 'attribute', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'markers'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '318', 'type': 'return_statement', 'children': ['319']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'markers'} | def return_markers(self):
ent_file = self._filename.with_suffix('.ent')
if not ent_file.exists():
ent_file = self._filename.with_suffix('.ent.old')
try:
ent_notes = _read_ent(ent_file)
except (FileNotFoundError, PermissionError):
markers = []
else:
allnote = []
for n in ent_notes:
try:
n['value'].keys()
allnote.append(n['value'])
except AttributeError:
lg.debug('Note of length {} was not '
'converted to dict'.format(n['length']))
s_freq = self._hdr['erd']['sample_freq']
pcname = '0CFEBE72-DA20-4b3a-A8AC-CDD41BFE2F0D'
note_time = []
note_name = []
note_note = []
for n in allnote:
if n['Text'] == 'Analyzed Data Note':
continue
if not n['Text']:
continue
if 'User' not in n['Data'].keys():
continue
user1 = n['Data']['User'] == 'Persyst'
user2 = False
user3 = n['Data']['User'] == pcname
user4 = n['Data']['User'] == 'XLSpike - Intracranial'
user5 = n['Data']['User'] == 'XLEvent - Intracranial'
if user1 or user2 or user3 or user4 or user5:
continue
if len(n['Data']['User']) == 0:
note_name.append('-unknown-')
else:
note_name.append(n['Data']['User'].split()[0])
note_time.append(n['Stamp'] / s_freq)
note_note.append(n['Text'])
markers = []
for time, name, note in zip(note_time, note_name, note_note):
m = {'name': note + ' (' + name + ')',
'start': time,
'end': time,
'chan': None,
}
markers.append(m)
return markers |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'band_power'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'scaling'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'power'"}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'n_fft'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'detrend'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'array_out'}, {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19', '65', '106', '129', '139', '149', '184', '235', '330']}, {'id': '19', 'type': 'if_statement', 'children': ['20', '22', '31']}; {'id': '20', 'type': 'not_operator', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'array_out'}; {'id': '22', 'type': 'block', 'children': ['23', '27']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'power'}; {'id': '26', 'type': 'dictionary', 'children': []}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'peakf'}; {'id': '30', 'type': 'dictionary', 'children': []}, {'id': '31', 'type': 'else_clause', 'children': ['32']}; {'id': '32', 'type': 'block', 'children': ['33', '49']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'power'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'tuple', 'children': ['40', '48']}; {'id': '40', 'type': 'subscript', 'children': ['41', '47']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'number_of'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'string', 'children': [], 'value': "'chan'"}, {'id': '47', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'peakf'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'tuple', 'children': ['56', '64']}; {'id': '56', 'type': 'subscript', 'children': ['57', '63']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'number_of'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'chan'"}, {'id': '63', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '71', '76', '99']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'ChanFreq'}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'Sxx'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '76', 'type': 'elif_clause', 'children': ['77', '82']}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'ChanTime'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'Sxx'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'frequency'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90', '93', '96']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'scaling'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'scaling'}, {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'n_fft'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'n_fft'}; {'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'detrend'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'detrend'}, {'id': '99', 'type': 'else_clause', 'children': ['100']}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'raise_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'string', 'children': [], 'value': "'Invalid data type'"}; {'id': '106', 'type': 'if_statement', 'children': ['107', '110']}, {'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'is'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'detrend'}, {'id': '109', 'type': 'None', 'children': []}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'if_statement', 'children': ['112', '115', '120']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '=='}, {'id': '113', 'type': 'string', 'children': [], 'value': "'power'"}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'scaling'}, {'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': 'detrend'}, {'id': '119', 'type': 'string', 'children': [], 'value': "'linear'"}; {'id': '120', 'type': 'elif_clause', 'children': ['121', '124']}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': '=='}; {'id': '122', 'type': 'string', 'children': [], 'value': "'energy'"}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'scaling'}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'detrend'}; {'id': '128', 'type': 'None', 'children': []}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'sf'}; {'id': '132', 'type': 'subscript', 'children': ['133', '138']}, {'id': '133', 'type': 'subscript', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'Sxx'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '137', 'type': 'string', 'children': [], 'value': "'freq'"}; {'id': '138', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'f_res'}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '146'], 'value': '-'}, {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'sf'}, {'id': '145', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'sf'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '149', 'type': 'if_statement', 'children': ['150', '155', '178']}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '154'], 'value': 'is'}, {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '153', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '154', 'type': 'None', 'children': []}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'idx_f1'}, {'id': '159', 'type': 'call', 'children': ['160', '177']}; {'id': '160', 'type': 'attribute', 'children': ['161', '176']}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'asarray'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'list_comprehension', 'children': ['165', '173']}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'binary_operator', 'children': ['169', '170'], 'value': '-'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '173', 'type': 'for_in_clause', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'sf'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'argmin'}, {'id': '177', 'type': 'argument_list', 'children': []}; {'id': '178', 'type': 'else_clause', 'children': ['179']}, {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'idx_f1'}, {'id': '183', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '184', 'type': 'if_statement', 'children': ['185', '190', '224']}, {'id': '185', 'type': 'comparison_operator', 'children': ['186', '189'], 'value': 'is'}; {'id': '186', 'type': 'subscript', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '188', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '189', 'type': 'None', 'children': []}; {'id': '190', 'type': 'block', 'children': ['191']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'idx_f2'}; {'id': '194', 'type': 'call', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '218']}, {'id': '197', 'type': 'binary_operator', 'children': ['198', '217'], 'value': '+'}; {'id': '198', 'type': 'call', 'children': ['199', '216']}, {'id': '199', 'type': 'attribute', 'children': ['200', '215']}; {'id': '200', 'type': 'call', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'list_comprehension', 'children': ['204', '212']}; {'id': '204', 'type': 'call', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'binary_operator', 'children': ['208', '209'], 'value': '-'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '209', 'type': 'subscript', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '211', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '212', 'type': 'for_in_clause', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'sf'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'argmin'}; {'id': '216', 'type': 'argument_list', 'children': []}, {'id': '217', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '218', 'type': 'binary_operator', 'children': ['219', '223'], 'value': '-'}, {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'sf'}, {'id': '223', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '224', 'type': 'else_clause', 'children': ['225']}, {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'assignment', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'idx_f2'}, {'id': '229', 'type': 'binary_operator', 'children': ['230', '234'], 'value': '-'}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'sf'}; {'id': '234', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '235', 'type': 'for_statement', 'children': ['236', '239', '249']}; {'id': '236', 'type': 'pattern_list', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'subscript', 'children': ['243', '248']}, {'id': '243', 'type': 'subscript', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'Sxx'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '247', 'type': 'string', 'children': [], 'value': "'chan'"}; {'id': '248', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '249', 'type': 'block', 'children': ['250', '261', '275', '288', '299']}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'assignment', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '253', 'type': 'subscript', 'children': ['254', '260']}; {'id': '254', 'type': 'call', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'Sxx'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '260', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'pw'}; {'id': '264', 'type': 'binary_operator', 'children': ['265', '274'], 'value': '*'}, {'id': '265', 'type': 'call', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'subscript', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '270', 'type': 'slice', 'children': ['271', '272', '273']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'idx_f1'}; {'id': '272', 'type': 'colon', 'children': []}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'idx_f2'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'f_res'}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'idx_peak'}; {'id': '278', 'type': 'call', 'children': ['279', '287']}, {'id': '279', 'type': 'attribute', 'children': ['280', '286']}; {'id': '280', 'type': 'subscript', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '282', 'type': 'slice', 'children': ['283', '284', '285']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'idx_f1'}; {'id': '284', 'type': 'colon', 'children': []}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'idx_f2'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'argmax'}, {'id': '287', 'type': 'argument_list', 'children': []}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}, {'id': '289', 'type': 'assignment', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'pf'}, {'id': '291', 'type': 'subscript', 'children': ['292', '298']}; {'id': '292', 'type': 'subscript', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'sf'}; {'id': '294', 'type': 'slice', 'children': ['295', '296', '297']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'idx_f1'}; {'id': '296', 'type': 'colon', 'children': []}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'idx_f2'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'idx_peak'}, {'id': '299', 'type': 'if_statement', 'children': ['300', '301', '316']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'array_out'}, {'id': '301', 'type': 'block', 'children': ['302', '309']}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'assignment', 'children': ['304', '308']}; {'id': '304', 'type': 'subscript', 'children': ['305', '306', '307']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'power'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '307', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'pw'}, {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'assignment', 'children': ['311', '315']}, {'id': '311', 'type': 'subscript', 'children': ['312', '313', '314']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'peakf'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '314', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'pf'}; {'id': '316', 'type': 'else_clause', 'children': ['317']}, {'id': '317', 'type': 'block', 'children': ['318', '324']}; {'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': 'power'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'pw'}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}, {'id': '325', 'type': 'assignment', 'children': ['326', '329']}; {'id': '326', 'type': 'subscript', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'peakf'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'pf'}; {'id': '330', 'type': 'return_statement', 'children': ['331']}, {'id': '331', 'type': 'expression_list', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'power'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'peakf'} | def band_power(data, freq, scaling='power', n_fft=None, detrend=None,
array_out=False):
if not array_out:
power = {}
peakf = {}
else:
power = zeros((data.number_of('chan')[0], 1))
peakf = zeros((data.number_of('chan')[0], 1))
if isinstance(data, ChanFreq):
Sxx = data
elif isinstance(data, ChanTime):
Sxx = frequency(data, scaling=scaling, n_fft=n_fft, detrend=detrend)
else:
raise ValueError('Invalid data type')
if detrend is None:
if 'power' == scaling:
detrend = 'linear'
elif 'energy' == scaling:
detrend = None
sf = Sxx.axis['freq'][0]
f_res = sf[1] - sf[0]
if freq[0] is not None:
idx_f1 = asarray([abs(x - freq[0]) for x in sf]).argmin()
else:
idx_f1 = 0
if freq[1] is not None:
idx_f2 = min(asarray([abs(x - freq[1]) for x in sf]).argmin() + 1,
len(sf) - 1)
else:
idx_f2 = len(sf) - 1
for i, chan in enumerate(Sxx.axis['chan'][0]):
s = Sxx(chan=chan)[0]
pw = sum(s[idx_f1:idx_f2]) * f_res
idx_peak = s[idx_f1:idx_f2].argmax()
pf = sf[idx_f1:idx_f2][idx_peak]
if array_out:
power[i, 0] = pw
peakf[i, 0] = pf
else:
power[chan] = pw
peakf[chan] = pf
return power, peakf |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'morlet'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 's_freq'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ratio'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '5'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'sigma_f'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'dur_in_sd'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'dur_in_s'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'normalization'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'peak'"}, {'id': '21', 'type': 'default_parameter', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'zero_mean'}, {'id': '23', 'type': 'False', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25', '44', '55', '72', '85', '101', '116', '133', '150', '195', '212', '242']}, {'id': '25', 'type': 'if_statement', 'children': ['26', '29', '36']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'sigma_f'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sigma_f'}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '/'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ratio'}; {'id': '36', 'type': 'else_clause', 'children': ['37']}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ratio'}, {'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '/'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sigma_f'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'sigma_t'}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '/'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '49', 'type': 'parenthesized_expression', 'children': ['50'], 'value': '()'}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '54'], 'value': '*'}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '*'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sigma_f'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '62']}; {'id': '56', 'type': 'boolean_operator', 'children': ['57', '60'], 'value': 'and'}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': '<'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ratio'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '60', 'type': 'not_operator', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'zero_mean'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'lg'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'concatenated_string', 'children': ['70', '71']}; {'id': '70', 'type': 'string', 'children': [], 'value': "'The wavelet won\\'t have zero mean, set zero_mean=True to '"}, {'id': '71', 'type': 'string', 'children': [], 'value': "'correct it'"}; {'id': '72', 'type': 'if_statement', 'children': ['73', '76']}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'is'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'dur_in_s'}, {'id': '75', 'type': 'None', 'children': []}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'dur_in_s'}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '84'], 'value': '*'}, {'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '*'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'sigma_t'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'dur_in_sd'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'arange'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '95', '98']}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '94'], 'value': '/'}; {'id': '92', 'type': 'unary_operator', 'children': ['93'], 'value': '-'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'dur_in_s'}; {'id': '94', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '/'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'dur_in_s'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '100'], 'value': '/'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'binary_operator', 'children': ['108', '115'], 'value': '*'}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '114'], 'value': '*'}, {'id': '109', 'type': 'binary_operator', 'children': ['110', '113'], 'value': '*'}; {'id': '110', 'type': 'binary_operator', 'children': ['111', '112'], 'value': '*'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '1j'}; {'id': '112', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '116', 'type': 'if_statement', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'zero_mean'}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'augmented_assignment', 'children': ['121', '122'], 'value': '-='}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'binary_operator', 'children': ['126', '130'], 'value': '*'}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '129'], 'value': '/'}, {'id': '127', 'type': 'unary_operator', 'children': ['128'], 'value': '-'}; {'id': '128', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '129', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '**'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'ratio'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'augmented_assignment', 'children': ['135', '136'], 'value': '*='}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'binary_operator', 'children': ['140', '144'], 'value': '/'}; {'id': '140', 'type': 'unary_operator', 'children': ['141'], 'value': '-'}, {'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '**'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 't'}, {'id': '143', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '144', 'type': 'parenthesized_expression', 'children': ['145'], 'value': '()'}, {'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '*'}; {'id': '146', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '**'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'sigma_t'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '150', 'type': 'if_statement', 'children': ['151', '154', '169', '189']}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': '=='}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'normalization'}, {'id': '153', 'type': 'string', 'children': [], 'value': "'area'"}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'augmented_assignment', 'children': ['157', '158'], 'value': '/='}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'sqrt'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '168'], 'value': '*'}; {'id': '162', 'type': 'binary_operator', 'children': ['163', '167'], 'value': '*'}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'sqrt'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'pi'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'sigma_t'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '169', 'type': 'elif_clause', 'children': ['170', '173']}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': '=='}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'normalization'}; {'id': '172', 'type': 'string', 'children': [], 'value': "'max'"}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'augmented_assignment', 'children': ['176', '177'], 'value': '/='}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '177', 'type': 'binary_operator', 'children': ['178', '188'], 'value': '/'}; {'id': '178', 'type': 'binary_operator', 'children': ['179', '182'], 'value': '*'}, {'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '*'}; {'id': '180', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'sigma_t'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'sqrt'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '*'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'pi'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '189', 'type': 'elif_clause', 'children': ['190', '193']}; {'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': '=='}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'normalization'}; {'id': '192', 'type': 'string', 'children': [], 'value': "'peak'"}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'pass_statement', 'children': []}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'lg'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '207']}; {'id': '202', 'type': 'attribute', 'children': ['203', '206']}, {'id': '203', 'type': 'concatenated_string', 'children': ['204', '205']}; {'id': '204', 'type': 'string', 'children': [], 'value': "'At freq {0: 9.3f}Hz, sigma_f={1: 9.3f}Hz, sigma_t={2: 9.3f}s, '"}, {'id': '205', 'type': 'string', 'children': [], 'value': "'total duration={3: 9.3f}s'"}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '207', 'type': 'argument_list', 'children': ['208', '209', '210', '211']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'sigma_f'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'sigma_t'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'dur_in_s'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'lg'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '224']}, {'id': '219', 'type': 'attribute', 'children': ['220', '223']}; {'id': '220', 'type': 'concatenated_string', 'children': ['221', '222']}, {'id': '221', 'type': 'string', 'children': [], 'value': "' Real peak={0: 9.3f}, Mean={1: 12.6f}, '"}; {'id': '222', 'type': 'string', 'children': [], 'value': "'Energy={2: 9.3f}'"}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '224', 'type': 'argument_list', 'children': ['225', '232', '236']}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'call', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'real'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '232', 'type': 'call', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '236', 'type': 'binary_operator', 'children': ['237', '241'], 'value': '**'}, {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'norm'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '241', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '242', 'type': 'return_statement', 'children': ['243']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'w'} | def morlet(freq, s_freq, ratio=5, sigma_f=None, dur_in_sd=4, dur_in_s=None,
normalization='peak', zero_mean=False):
if sigma_f is None:
sigma_f = freq / ratio
else:
ratio = freq / sigma_f
sigma_t = 1 / (2 * pi * sigma_f)
if ratio < 5 and not zero_mean:
lg.info('The wavelet won\'t have zero mean, set zero_mean=True to '
'correct it')
if dur_in_s is None:
dur_in_s = sigma_t * dur_in_sd * 2
t = arange(-dur_in_s / 2, dur_in_s / 2, 1 / s_freq)
w = exp(1j * 2 * pi * freq * t)
if zero_mean:
w -= exp(-1 / 2 * ratio ** 2)
w *= exp(-t ** 2 / (2 * sigma_t ** 2))
if normalization == 'area':
w /= sqrt(sqrt(pi) * sigma_t * s_freq)
elif normalization == 'max':
w /= 2 * sigma_t * sqrt(2 * pi) / s_freq
elif normalization == 'peak':
pass
lg.info('At freq {0: 9.3f}Hz, sigma_f={1: 9.3f}Hz, sigma_t={2: 9.3f}s, '
'total duration={3: 9.3f}s'.format(freq, sigma_f, sigma_t,
dur_in_s))
lg.debug(' Real peak={0: 9.3f}, Mean={1: 12.6f}, '
'Energy={2: 9.3f}'.format(max(real(w)), mean(w), norm(w) ** 2))
return w |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_convert_timestr_to_seconds'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'time_str'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'rec_start'}; {'id': '6', 'type': 'block', 'children': ['7', '21', '120']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '15']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'CHECK_TIME_STR'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'time_str'}, {'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': 'ValueError'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'Input can only contain digits and colons'"}, {'id': '21', 'type': 'if_statement', 'children': ['22', '25', '111']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'in'}, {'id': '23', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'time_str'}, {'id': '25', 'type': 'block', 'children': ['26', '42', '57', '65', '79', '97']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'time_split'}, {'id': '29', 'type': 'list_comprehension', 'children': ['30', '34']}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '34', 'type': 'for_in_clause', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'time_str'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '42', 'type': 'if_statement', 'children': ['43', '49']}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '48'], 'value': '=='}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'time_split'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'time_split'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'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': 'clock_time'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'list_splat', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'time_split'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'chosen_start'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'combine'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '78']}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'rec_start'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '77', 'type': 'argument_list', 'children': []}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'clock_time'}, {'id': '79', 'type': 'if_statement', 'children': ['80', '87']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': '<'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'clock_time'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'rec_start'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '86', 'type': 'argument_list', 'children': []}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'augmented_assignment', 'children': ['90', '91'], 'value': '+='}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'chosen_start'}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'timedelta'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'days'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'window_start'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '110']}; {'id': '104', 'type': 'attribute', 'children': ['105', '109']}, {'id': '105', 'type': 'parenthesized_expression', 'children': ['106'], 'value': '()'}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '-'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'chosen_start'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'rec_start'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'total_seconds'}; {'id': '110', 'type': 'argument_list', 'children': []}, {'id': '111', 'type': 'else_clause', 'children': ['112']}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'window_start'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'time_str'}; {'id': '120', 'type': 'return_statement', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'window_start'} | def _convert_timestr_to_seconds(time_str, rec_start):
if not CHECK_TIME_STR.match(time_str):
raise ValueError('Input can only contain digits and colons')
if ':' in time_str:
time_split = [int(x) for x in time_str.split(':')]
if len(time_split) == 2:
time_split.append(0)
clock_time = time(*time_split)
chosen_start = datetime.combine(rec_start.date(), clock_time)
if clock_time < rec_start.time():
chosen_start += timedelta(days=1)
window_start = int((chosen_start - rec_start).total_seconds())
else:
window_start = int(time_str)
return window_start |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'mouseReleaseEvent'}, {'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', '14', '20', '32', '39', '55', '71', '82', '362', '368', '376']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '12']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'scene'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': []}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'event_sel'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'return_statement', 'children': []}; {'id': '20', 'type': 'if_statement', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'deselect'}; {'id': '24', 'type': 'block', 'children': ['25', '31']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'deselect'}; {'id': '30', 'type': 'False', 'children': []}, {'id': '31', 'type': 'return_statement', 'children': []}; {'id': '32', 'type': 'if_statement', 'children': ['33', '37']}, {'id': '33', 'type': 'not_operator', 'children': ['34']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'ready'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'return_statement', 'children': []}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'chk_marker'}; {'id': '42', 'type': 'call', 'children': ['43', '54']}, {'id': '43', 'type': 'attribute', 'children': ['44', '53']}; {'id': '44', 'type': 'subscript', 'children': ['45', '52']}, {'id': '45', 'type': 'attribute', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'notes'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'new_bookmark'"}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'isChecked'}; {'id': '54', 'type': 'argument_list', 'children': []}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'chk_event'}; {'id': '58', 'type': 'call', 'children': ['59', '70']}, {'id': '59', 'type': 'attribute', 'children': ['60', '69']}; {'id': '60', 'type': 'subscript', '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': 'parent'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'notes'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'new_event'"}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'isChecked'}; {'id': '70', 'type': 'argument_list', 'children': []}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'y_distance'}; {'id': '74', 'type': 'call', 'children': ['75', '80']}, {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'string', 'children': [], 'value': "'y_distance'"}; {'id': '82', 'type': 'if_statement', 'children': ['83', '86', '310']}, {'id': '83', 'type': 'boolean_operator', 'children': ['84', '85'], 'value': 'or'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'chk_marker'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'chk_event'}; {'id': '86', 'type': 'block', 'children': ['87', '104', '121']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'x_in_scene'}; {'id': '90', 'type': 'call', 'children': ['91', '103']}, {'id': '91', 'type': 'attribute', 'children': ['92', '102']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'mapToScene'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '101', 'type': 'argument_list', 'children': []}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '103', 'type': 'argument_list', 'children': []}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'y_in_scene'}, {'id': '107', 'type': 'call', 'children': ['108', '120']}; {'id': '108', 'type': 'attribute', 'children': ['109', '119']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'mapToScene'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'event'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '118', 'type': 'argument_list', 'children': []}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '120', 'type': 'argument_list', 'children': []}, {'id': '121', 'type': 'if_statement', 'children': ['122', '129']}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '128'], 'value': 'is'}, {'id': '123', 'type': 'subscript', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'sel_xy'}, {'id': '127', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '128', 'type': 'None', 'children': []}, {'id': '129', 'type': 'block', 'children': ['130', '144', '158', '169', '176', '197', '216']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '133', 'type': 'subscript', 'children': ['134', '143']}; {'id': '134', 'type': 'attribute', 'children': ['135', '142']}, {'id': '135', 'type': 'attribute', 'children': ['136', '141']}; {'id': '136', 'type': 'attribute', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'dataset'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'header'}, {'id': '143', 'type': 'string', 'children': [], 'value': "'s_freq'"}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'at_s_freq'}, {'id': '147', 'type': 'lambda', 'children': ['148', '150']}; {'id': '148', 'type': 'lambda_parameters', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '150', 'type': 'binary_operator', 'children': ['151', '157'], 'value': '/'}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'round'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '*'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 's_freq'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 's_freq'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'at_s_freq'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'subscript', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'sel_xy'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '172', 'type': 'call', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'at_s_freq'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'x_in_scene'}; {'id': '176', 'type': 'if_statement', 'children': ['177', '192']}, {'id': '177', 'type': 'comparison_operator', 'children': ['178', '184'], 'value': '<'}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'binary_operator', 'children': ['182', '183'], 'value': '-'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'start'}; {'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': 'parent'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'string', 'children': [], 'value': "'min_marker_dur'"}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '197', 'type': 'if_statement', 'children': ['198', '201', '208']}; {'id': '198', 'type': 'comparison_operator', 'children': ['199', '200'], 'value': '<='}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '201', 'type': 'block', 'children': ['202']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '205', 'type': 'tuple', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '208', 'type': 'else_clause', 'children': ['209']}, {'id': '209', 'type': 'block', 'children': ['210']}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '213', 'type': 'tuple', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '216', 'type': 'if_statement', 'children': ['217', '218', '230']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'chk_marker'}; {'id': '218', 'type': 'block', 'children': ['219']}, {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'call', 'children': ['221', '228']}, {'id': '221', 'type': 'attribute', 'children': ['222', '227']}; {'id': '222', 'type': 'attribute', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'notes'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'add_bookmark'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '230', 'type': 'elif_clause', 'children': ['231', '236']}, {'id': '231', 'type': 'boolean_operator', 'children': ['232', '233'], 'value': 'and'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'chk_event'}, {'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': '!='}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '236', 'type': 'block', 'children': ['237', '251', '297']}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'eventtype'}; {'id': '240', 'type': 'call', 'children': ['241', '250']}, {'id': '241', 'type': 'attribute', 'children': ['242', '249']}; {'id': '242', 'type': 'attribute', 'children': ['243', '248']}, {'id': '243', 'type': 'attribute', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'notes'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'idx_eventtype'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'currentText'}; {'id': '250', 'type': 'argument_list', 'children': []}, {'id': '251', 'type': 'if_statement', 'children': ['252', '266', '271']}; {'id': '252', 'type': 'comparison_operator', 'children': ['253', '263'], 'value': '>'}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'abs'}, {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'binary_operator', 'children': ['257', '258'], 'value': '-'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'y_in_scene'}; {'id': '258', 'type': 'subscript', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'sel_xy'}; {'id': '262', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '263', 'type': 'binary_operator', 'children': ['264', '265'], 'value': '*'}; {'id': '264', 'type': 'float', 'children': [], 'value': '1.5'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'y_distance'}; {'id': '266', 'type': 'block', 'children': ['267']}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'assignment', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '270', 'type': 'string', 'children': [], 'value': "''"}, {'id': '271', 'type': 'else_clause', 'children': ['272']}; {'id': '272', 'type': 'block', 'children': ['273', '289']}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'chan_idx'}; {'id': '276', 'type': 'call', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}, {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'floor'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'binary_operator', 'children': ['283', '288'], 'value': '/'}, {'id': '283', 'type': 'subscript', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'sel_xy'}, {'id': '287', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'y_distance'}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '292', 'type': 'subscript', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'chan_idx'}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'call', 'children': ['299', '306']}, {'id': '299', 'type': 'attribute', 'children': ['300', '305']}; {'id': '300', 'type': 'attribute', 'children': ['301', '304']}, {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'notes'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'add_event'}; {'id': '306', 'type': 'argument_list', 'children': ['307', '308', '309']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'eventtype'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '310', 'type': 'else_clause', 'children': ['311']}, {'id': '311', 'type': 'block', 'children': ['312', '336', '342', '352']}; {'id': '312', 'type': 'if_statement', 'children': ['313', '324']}, {'id': '313', 'type': 'comparison_operator', 'children': ['314', '317'], 'value': 'in'}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'idx_info'}, {'id': '317', 'type': 'call', 'children': ['318', '323']}; {'id': '318', 'type': 'attribute', 'children': ['319', '322']}, {'id': '319', 'type': 'attribute', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'scene'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '323', 'type': 'argument_list', 'children': []}; {'id': '324', 'type': 'block', 'children': ['325']}, {'id': '325', 'type': 'expression_statement', 'children': ['326']}; {'id': '326', 'type': 'call', 'children': ['327', '332']}, {'id': '327', 'type': 'attribute', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'scene'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'removeItem'}; {'id': '332', 'type': 'argument_list', 'children': ['333']}, {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'idx_info'}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}, {'id': '337', 'type': 'assignment', 'children': ['338', '341']}; {'id': '338', 'type': 'attribute', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'idx_info'}, {'id': '341', 'type': 'None', 'children': []}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}, {'id': '343', 'type': 'call', 'children': ['344', '351']}; {'id': '344', 'type': 'attribute', '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': 'parent'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'spectrum'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '351', 'type': 'argument_list', 'children': []}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}, {'id': '353', 'type': 'call', 'children': ['354', '361']}; {'id': '354', 'type': 'attribute', 'children': ['355', '360']}, {'id': '355', 'type': 'attribute', 'children': ['356', '359']}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'spectrum'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'display_window'}, {'id': '361', 'type': 'argument_list', 'children': []}; {'id': '362', 'type': 'expression_statement', 'children': ['363']}, {'id': '363', 'type': 'assignment', 'children': ['364', '367']}; {'id': '364', 'type': 'attribute', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'sel_chan'}, {'id': '367', 'type': 'None', 'children': []}; {'id': '368', 'type': 'expression_statement', 'children': ['369']}, {'id': '369', 'type': 'assignment', 'children': ['370', '373']}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'sel_xy'}, {'id': '373', 'type': 'tuple', 'children': ['374', '375']}; {'id': '374', 'type': 'None', 'children': []}, {'id': '375', 'type': 'None', 'children': []}; {'id': '376', 'type': 'if_statement', 'children': ['377', '388']}, {'id': '377', 'type': 'comparison_operator', 'children': ['378', '381'], 'value': 'in'}; {'id': '378', 'type': 'attribute', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'idx_sel'}, {'id': '381', 'type': 'call', 'children': ['382', '387']}; {'id': '382', 'type': 'attribute', 'children': ['383', '386']}, {'id': '383', 'type': 'attribute', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'scene'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '387', 'type': 'argument_list', 'children': []}; {'id': '388', 'type': 'block', 'children': ['389', '400']}, {'id': '389', 'type': 'expression_statement', 'children': ['390']}; {'id': '390', 'type': 'call', 'children': ['391', '396']}, {'id': '391', 'type': 'attribute', 'children': ['392', '395']}; {'id': '392', 'type': 'attribute', 'children': ['393', '394']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'scene'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'removeItem'}; {'id': '396', 'type': 'argument_list', 'children': ['397']}, {'id': '397', 'type': 'attribute', 'children': ['398', '399']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'idx_sel'}; {'id': '400', 'type': 'expression_statement', 'children': ['401']}, {'id': '401', 'type': 'assignment', 'children': ['402', '405']}; {'id': '402', 'type': 'attribute', 'children': ['403', '404']}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'idx_sel'}, {'id': '405', 'type': 'None', 'children': []} | def mouseReleaseEvent(self, event):
if not self.scene:
return
if self.event_sel:
return
if self.deselect:
self.deselect = False
return
if not self.ready:
return
chk_marker = self.parent.notes.action['new_bookmark'].isChecked()
chk_event = self.parent.notes.action['new_event'].isChecked()
y_distance = self.parent.value('y_distance')
if chk_marker or chk_event:
x_in_scene = self.mapToScene(event.pos()).x()
y_in_scene = self.mapToScene(event.pos()).y()
if self.sel_xy[0] is not None:
s_freq = self.parent.info.dataset.header['s_freq']
at_s_freq = lambda x: round(x * s_freq) / s_freq
start = at_s_freq(self.sel_xy[0])
end = at_s_freq(x_in_scene)
if abs(end - start) < self.parent.value('min_marker_dur'):
end = start
if start <= end:
time = (start, end)
else:
time = (end, start)
if chk_marker:
self.parent.notes.add_bookmark(time)
elif chk_event and start != end:
eventtype = self.parent.notes.idx_eventtype.currentText()
if abs(y_in_scene - self.sel_xy[1]) > 1.5 * y_distance:
chan = ''
else:
chan_idx = int(floor(self.sel_xy[1] / y_distance))
chan = self.chan[chan_idx]
self.parent.notes.add_event(eventtype, time, chan)
else:
if self.idx_info in self.scene.items():
self.scene.removeItem(self.idx_info)
self.idx_info = None
self.parent.spectrum.update()
self.parent.spectrum.display_window()
self.sel_chan = None
self.sel_xy = (None, None)
if self.idx_sel in self.scene.items():
self.scene.removeItem(self.idx_sel)
self.idx_sel = None |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'next_event'}, {'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': 'delete'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '65', '71', '77', '85', '129', '141', '160', '216', '230', '292', '298', '307']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'delete'}, {'id': '11', 'type': 'block', 'children': ['12', '16', '27', '40', '49', '57']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '15', 'type': 'string', 'children': [], 'value': '"Delete this event? This cannot be undone."'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'msgbox'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '25', '26']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Question'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'Delete event'"}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'msgbox'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'setStandardButtons'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '37'], 'value': '|'}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'Yes'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'No'}; {'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': 'msgbox'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'setDefaultButton'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'Yes'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'msgbox'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'exec_'}; {'id': '56', 'type': 'argument_list', 'children': []}, {'id': '57', 'type': 'if_statement', 'children': ['58', '63']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '=='}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'QMessageBox'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'No'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'return_statement', 'children': []}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'event_sel'}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'event_sel'}, {'id': '71', 'type': 'if_statement', 'children': ['72', '75']}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'event_sel'}; {'id': '74', 'type': 'None', 'children': []}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'return_statement', 'children': []}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'notes'}; {'id': '80', 'type': 'attribute', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'notes'}, {'id': '85', 'type': 'if_statement', 'children': ['86', '90', '121']}; {'id': '86', 'type': 'not_operator', 'children': ['87']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'current_event_row'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'notes'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'find_row'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '106']}, {'id': '99', 'type': 'call', 'children': ['100', '105']}; {'id': '100', 'type': 'attribute', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'event_sel'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'marker'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '105', 'type': 'argument_list', 'children': []}; {'id': '106', 'type': 'binary_operator', 'children': ['107', '114'], 'value': '+'}, {'id': '107', 'type': 'call', 'children': ['108', '113']}; {'id': '108', 'type': 'attribute', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'event_sel'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'marker'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '113', 'type': 'argument_list', 'children': []}; {'id': '114', 'type': 'call', 'children': ['115', '120']}, {'id': '115', 'type': 'attribute', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'event_sel'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'marker'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '120', 'type': 'argument_list', 'children': []}, {'id': '121', 'type': 'else_clause', 'children': ['122']}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'current_event_row'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'same_type'}; {'id': '132', 'type': 'call', 'children': ['133', '140']}, {'id': '133', 'type': 'attribute', 'children': ['134', '139']}; {'id': '134', 'type': 'subscript', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'next_of_same_type'"}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'isChecked'}; {'id': '140', 'type': 'argument_list', 'children': []}, {'id': '141', 'type': 'if_statement', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'same_type'}, {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '147', 'type': 'call', 'children': ['148', '159']}; {'id': '148', 'type': 'attribute', 'children': ['149', '158']}, {'id': '149', 'type': 'call', 'children': ['150', '155']}; {'id': '150', 'type': 'attribute', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'notes'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'idx_annot_list'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '155', 'type': 'argument_list', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '157', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '159', 'type': 'argument_list', 'children': []}; {'id': '160', 'type': 'if_statement', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'delete'}; {'id': '162', 'type': 'block', 'children': ['163', '169', '199', '212']}, {'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': 'notes'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'delete_row'}; {'id': '168', 'type': 'argument_list', 'children': []}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'string', 'children': [], 'value': "'Deleted event from {} to {}.'"}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '184']}, {'id': '177', 'type': 'call', 'children': ['178', '183']}; {'id': '178', 'type': 'attribute', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'event_sel'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'marker'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '183', 'type': 'argument_list', 'children': []}; {'id': '184', 'type': 'binary_operator', 'children': ['185', '192'], 'value': '+'}, {'id': '185', 'type': 'call', 'children': ['186', '191']}; {'id': '186', 'type': 'attribute', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'event_sel'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'marker'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '191', 'type': 'argument_list', 'children': []}; {'id': '192', 'type': 'call', 'children': ['193', '198']}, {'id': '193', 'type': 'attribute', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'event_sel'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'marker'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '198', 'type': 'argument_list', 'children': []}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '210']}, {'id': '201', 'type': 'attribute', 'children': ['202', '209']}; {'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': 'parent'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'statusBar'}; {'id': '208', 'type': 'argument_list', 'children': []}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'showMessage'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'augmented_assignment', 'children': ['214', '215'], 'value': '-='}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '215', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '216', 'type': 'if_statement', 'children': ['217', '228']}, {'id': '217', 'type': 'comparison_operator', 'children': ['218', '221'], 'value': '=='}; {'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '+'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '220', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '221', 'type': 'call', 'children': ['222', '227']}; {'id': '222', 'type': 'attribute', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'notes'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'idx_annot_list'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'rowCount'}, {'id': '227', 'type': 'argument_list', 'children': []}; {'id': '228', 'type': 'block', 'children': ['229']}, {'id': '229', 'type': 'return_statement', 'children': []}; {'id': '230', 'type': 'if_statement', 'children': ['231', '233', '240']}, {'id': '231', 'type': 'not_operator', 'children': ['232']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'same_type'}, {'id': '233', 'type': 'block', 'children': ['234']}; {'id': '234', 'type': 'expression_statement', 'children': ['235']}, {'id': '235', 'type': 'assignment', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'next_row'}, {'id': '237', 'type': 'binary_operator', 'children': ['238', '239'], 'value': '+'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '239', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '240', 'type': 'else_clause', 'children': ['241']}, {'id': '241', 'type': 'block', 'children': ['242', '246', '263', '286']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'next_row'}, {'id': '245', 'type': 'None', 'children': []}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'types'}, {'id': '249', 'type': 'subscript', 'children': ['250', '258']}; {'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': 'notes'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'idx_annot_list'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'property'}; {'id': '256', 'type': 'argument_list', 'children': ['257']}, {'id': '257', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '258', 'type': 'slice', 'children': ['259', '262']}, {'id': '259', 'type': 'binary_operator', 'children': ['260', '261'], 'value': '+'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '261', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '262', 'type': 'colon', 'children': []}, {'id': '263', 'type': 'for_statement', 'children': ['264', '267', '271']}; {'id': '264', 'type': 'pattern_list', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'ty'}, {'id': '267', 'type': 'call', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'types'}, {'id': '271', 'type': 'block', 'children': ['272']}; {'id': '272', 'type': 'if_statement', 'children': ['273', '276']}, {'id': '273', 'type': 'comparison_operator', 'children': ['274', '275'], 'value': '=='}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'ty'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '276', 'type': 'block', 'children': ['277', '285']}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'assignment', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'next_row'}; {'id': '280', 'type': 'binary_operator', 'children': ['281', '284'], 'value': '+'}, {'id': '281', 'type': 'binary_operator', 'children': ['282', '283'], 'value': '+'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '283', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '285', 'type': 'break_statement', 'children': []}; {'id': '286', 'type': 'if_statement', 'children': ['287', '290']}, {'id': '287', 'type': 'comparison_operator', 'children': ['288', '289'], 'value': 'is'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'next_row'}, {'id': '289', 'type': 'None', 'children': []}; {'id': '290', 'type': 'block', 'children': ['291']}, {'id': '291', 'type': 'return_statement', 'children': []}; {'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': 'current_event_row'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'next_row'}; {'id': '298', 'type': 'expression_statement', 'children': ['299']}, {'id': '299', 'type': 'call', 'children': ['300', '303']}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'notes'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'go_to_marker'}, {'id': '303', 'type': 'argument_list', 'children': ['304', '305', '306']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'next_row'}, {'id': '305', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '306', 'type': 'string', 'children': [], 'value': "'annot'"}, {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'call', 'children': ['309', '314']}, {'id': '309', 'type': 'attribute', 'children': ['310', '313']}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'notes'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'idx_annot_list'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'setCurrentCell'}; {'id': '314', 'type': 'argument_list', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'next_row'} | def next_event(self, delete=False):
if delete:
msg = "Delete this event? This cannot be undone."
msgbox = QMessageBox(QMessageBox.Question, 'Delete event', msg)
msgbox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
msgbox.setDefaultButton(QMessageBox.Yes)
response = msgbox.exec_()
if response == QMessageBox.No:
return
event_sel = self.event_sel
if event_sel is None:
return
notes = self.parent.notes
if not self.current_event_row:
row = notes.find_row(event_sel.marker.x(),
event_sel.marker.x() + event_sel.marker.width())
else:
row = self.current_event_row
same_type = self.action['next_of_same_type'].isChecked()
if same_type:
target = notes.idx_annot_list.item(row, 2).text()
if delete:
notes.delete_row()
msg = 'Deleted event from {} to {}.'.format(event_sel.marker.x(),
event_sel.marker.x() + event_sel.marker.width())
self.parent.statusBar().showMessage(msg)
row -= 1
if row + 1 == notes.idx_annot_list.rowCount():
return
if not same_type:
next_row = row + 1
else:
next_row = None
types = notes.idx_annot_list.property('name')[row + 1:]
for i, ty in enumerate(types):
if ty == target:
next_row = row + 1 + i
break
if next_row is None:
return
self.current_event_row = next_row
notes.go_to_marker(next_row, 0, 'annot')
notes.idx_annot_list.setCurrentCell(next_row, 0) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'montage'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref_chan'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ref_to_avg'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'bipolar'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '16', 'type': 'string', 'children': [], 'value': "'average'"}, {'id': '17', 'type': 'block', 'children': ['18', '32', '66', '75', '150', '329']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24']}, {'id': '19', 'type': 'boolean_operator', 'children': ['20', '21'], 'value': 'and'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ref_to_avg'}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ref_chan'}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'raise_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'concatenated_string', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'You cannot specify reference to the average and '"}, {'id': '31', 'type': 'string', 'children': [], 'value': "'the channels to use as reference'"}; {'id': '32', 'type': 'if_statement', 'children': ['33', '36']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'is'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ref_chan'}, {'id': '35', 'type': 'None', 'children': []}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'if_statement', 'children': ['38', '60']}; {'id': '38', 'type': 'parenthesized_expression', 'children': ['39'], 'value': '()'}, {'id': '39', 'type': 'boolean_operator', 'children': ['40', '48'], 'value': 'or'}; {'id': '40', 'type': 'not_operator', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ref_chan'}, {'id': '45', 'type': 'tuple', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '48', 'type': 'not_operator', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '51', 'type': 'generator_expression', 'children': ['52', '57']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ref_chan'}; {'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': 'TypeError'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'string', 'children': [], 'value': "'chan should be a list of strings'"}; {'id': '66', 'type': 'if_statement', 'children': ['67', '70']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'is'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'ref_chan'}, {'id': '69', 'type': 'None', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'ref_chan'}; {'id': '74', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '75', 'type': 'if_statement', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'bipolar'}, {'id': '77', 'type': 'block', 'children': ['78', '91', '100', '110', '118', '132', '142']}; {'id': '78', 'type': 'if_statement', 'children': ['79', '85']}, {'id': '79', 'type': 'not_operator', 'children': ['80']}; {'id': '80', 'type': 'subscript', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'chan'"}, {'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': "'Data should have Chan information in attr'"}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': '_assert_equal_channels'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'subscript', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '99', 'type': 'string', 'children': [], 'value': "'chan'"}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'chan_in_data'}, {'id': '103', 'type': 'subscript', 'children': ['104', '109']}; {'id': '104', 'type': 'subscript', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'chan'"}, {'id': '109', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '113', 'type': 'subscript', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '117', 'type': 'string', 'children': [], 'value': "'chan'"}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'lambda', 'children': ['125', '127']}, {'id': '125', 'type': 'lambda_parameters', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '127', 'type': 'comparison_operator', 'children': ['128', '131'], 'value': 'in'}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'chan_in_data'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '137']}; {'id': '134', 'type': 'pattern_list', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'trans'}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'create_bipolar_chan'}, {'id': '139', 'type': 'argument_list', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'bipolar'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '149']}; {'id': '144', 'type': 'subscript', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'chan'"}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '150', 'type': 'if_statement', 'children': ['151', '156', '323']}, {'id': '151', 'type': 'boolean_operator', 'children': ['152', '155'], 'value': 'or'}; {'id': '152', 'type': 'boolean_operator', 'children': ['153', '154'], 'value': 'or'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'ref_to_avg'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'ref_chan'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'bipolar'}; {'id': '156', 'type': 'block', 'children': ['157', '165', '174']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'mdata'}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': '_copy'}; {'id': '164', 'type': 'argument_list', 'children': []}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'idx_chan'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'mdata'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'index_of'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'string', 'children': [], 'value': "'chan'"}; {'id': '174', 'type': 'for_statement', 'children': ['175', '176', '185']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'mdata'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'number_of'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'string', 'children': [], 'value': "'trial'"}, {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'if_statement', 'children': ['187', '190', '265']}, {'id': '187', 'type': 'boolean_operator', 'children': ['188', '189'], 'value': 'or'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ref_to_avg'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'ref_chan'}; {'id': '190', 'type': 'block', 'children': ['191', '204', '216']}, {'id': '191', 'type': 'if_statement', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'ref_to_avg'}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'ref_chan'}, {'id': '197', 'type': 'subscript', 'children': ['198', '203']}; {'id': '198', 'type': 'subscript', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'chan'"}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'ref_data'}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '209', 'type': 'argument_list', 'children': ['210', '213']}; {'id': '210', 'type': 'keyword_argument', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'trial'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'ref_chan'}; {'id': '216', 'type': 'if_statement', 'children': ['217', '220', '243']}, {'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': '=='}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '219', 'type': 'string', 'children': [], 'value': "'average'"}; {'id': '220', 'type': 'block', 'children': ['221']}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '228']}, {'id': '223', 'type': 'subscript', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'mdata'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '228', 'type': 'parenthesized_expression', 'children': ['229'], 'value': '()'}, {'id': '229', 'type': 'binary_operator', 'children': ['230', '236'], 'value': '-'}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'keyword_argument', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'trial'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '236', 'type': 'call', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '238', 'type': 'argument_list', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'ref_data'}; {'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'idx_chan'}, {'id': '243', 'type': 'elif_clause', 'children': ['244', '247']}; {'id': '244', 'type': 'comparison_operator', 'children': ['245', '246'], 'value': '=='}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '246', 'type': 'string', 'children': [], 'value': "'regression'"}, {'id': '247', 'type': 'block', 'children': ['248']}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'assignment', 'children': ['250', '255']}; {'id': '250', 'type': 'subscript', 'children': ['251', '254']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'mdata'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '255', 'type': 'call', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'compute_average_regress'}, {'id': '257', 'type': 'argument_list', 'children': ['258', '264']}; {'id': '258', 'type': 'call', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'trial'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'idx_chan'}, {'id': '265', 'type': 'elif_clause', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'bipolar'}, {'id': '267', 'type': 'block', 'children': ['268', '286', '303']}; {'id': '268', 'type': 'if_statement', 'children': ['269', '278']}, {'id': '269', 'type': 'not_operator', 'children': ['270']}; {'id': '270', 'type': 'comparison_operator', 'children': ['271', '277'], 'value': '=='}, {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'index_of'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'string', 'children': [], 'value': "'chan'"}, {'id': '277', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'ValueError'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'concatenated_string', 'children': ['284', '285']}; {'id': '284', 'type': 'string', 'children': [], 'value': "'For matrix multiplication to work, '"}, {'id': '285', 'type': 'string', 'children': [], 'value': "'the first dimension should be chan'"}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}, {'id': '287', 'type': 'assignment', 'children': ['288', '293']}; {'id': '288', 'type': 'subscript', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'mdata'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '293', 'type': 'call', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'dot'}, {'id': '295', 'type': 'argument_list', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'trans'}, {'id': '297', 'type': 'call', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'keyword_argument', 'children': ['301', '302']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'trial'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '312']}, {'id': '305', 'type': 'subscript', 'children': ['306', '311']}; {'id': '306', 'type': 'subscript', 'children': ['307', '310']}, {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'mdata'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '310', 'type': 'string', 'children': [], 'value': "'chan'"}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '312', 'type': 'call', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'asarray'}; {'id': '314', 'type': 'argument_list', 'children': ['315', '320']}, {'id': '315', 'type': 'call', 'children': ['316', '319']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'return_label'}, {'id': '319', 'type': 'argument_list', 'children': []}; {'id': '320', 'type': 'keyword_argument', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '322', 'type': 'string', 'children': [], 'value': "'U'"}, {'id': '323', 'type': 'else_clause', 'children': ['324']}; {'id': '324', 'type': 'block', 'children': ['325']}, {'id': '325', 'type': 'expression_statement', 'children': ['326']}; {'id': '326', 'type': 'assignment', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'mdata'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '329', 'type': 'return_statement', 'children': ['330']} | def montage(data, ref_chan=None, ref_to_avg=False, bipolar=None,
method='average'):
if ref_to_avg and ref_chan is not None:
raise TypeError('You cannot specify reference to the average and '
'the channels to use as reference')
if ref_chan is not None:
if (not isinstance(ref_chan, (list, tuple)) or
not all(isinstance(x, str) for x in ref_chan)):
raise TypeError('chan should be a list of strings')
if ref_chan is None:
ref_chan = []
if bipolar:
if not data.attr['chan']:
raise ValueError('Data should have Chan information in attr')
_assert_equal_channels(data.axis['chan'])
chan_in_data = data.axis['chan'][0]
chan = data.attr['chan']
chan = chan(lambda x: x.label in chan_in_data)
chan, trans = create_bipolar_chan(chan, bipolar)
data.attr['chan'] = chan
if ref_to_avg or ref_chan or bipolar:
mdata = data._copy()
idx_chan = mdata.index_of('chan')
for i in range(mdata.number_of('trial')):
if ref_to_avg or ref_chan:
if ref_to_avg:
ref_chan = data.axis['chan'][i]
ref_data = data(trial=i, chan=ref_chan)
if method == 'average':
mdata.data[i] = (data(trial=i) - mean(ref_data, axis=idx_chan))
elif method == 'regression':
mdata.data[i] = compute_average_regress(data(trial=i), idx_chan)
elif bipolar:
if not data.index_of('chan') == 0:
raise ValueError('For matrix multiplication to work, '
'the first dimension should be chan')
mdata.data[i] = dot(trans, data(trial=i))
mdata.axis['chan'][i] = asarray(chan.return_label(),
dtype='U')
else:
mdata = data
return mdata |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_artf_evts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'annot'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'min_dur'}, {'id': '11', 'type': 'float', 'children': [], 'value': '0.1'}; {'id': '12', 'type': 'block', 'children': ['13', '17', '25', '35', '44', '66', '237']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'new_times'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'beg'}; {'id': '20', 'type': 'subscript', 'children': ['21', '24']}, {'id': '21', 'type': 'subscript', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '28', 'type': 'subscript', 'children': ['29', '33']}, {'id': '29', 'type': 'subscript', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'times'}, {'id': '31', 'type': 'unary_operator', 'children': ['32'], 'value': '-'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '33', 'type': 'unary_operator', 'children': ['34'], 'value': '-'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '38', 'type': 'conditional_expression', 'children': ['39', '42', '43'], 'value': 'if'}, {'id': '39', 'type': 'tuple', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '41', 'type': 'string', 'children': [], 'value': "''"}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'artefact'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'annot'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'get_events'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '55', '60', '63']}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'Artefact'"}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '57', 'type': 'tuple', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'beg'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'chan'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'chan'}, {'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'qual'}, {'id': '65', 'type': 'string', 'children': [], 'value': "'Good'"}; {'id': '66', 'type': 'if_statement', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'artefact'}; {'id': '68', 'type': 'block', 'children': ['69', '73']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'new_times'}; {'id': '72', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'times'}; {'id': '76', 'type': 'block', 'children': ['77', '81', '85']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'reject'}; {'id': '80', 'type': 'False', 'children': []}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'new_seg'}; {'id': '84', 'type': 'True', 'children': []}, {'id': '85', 'type': 'while_statement', 'children': ['86', '89']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'is'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'new_seg'}; {'id': '88', 'type': 'False', 'children': []}, {'id': '89', 'type': 'block', 'children': ['90', '102', '108', '215']}; {'id': '90', 'type': 'if_statement', 'children': ['91', '97']}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '96'], 'value': 'is'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'new_seg'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'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': 'seg'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'new_seg'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'for_statement', 'children': ['109', '110', '111']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'artf'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'artefact'}, {'id': '111', 'type': 'block', 'children': ['112', '138', '151', '164', '211']}; {'id': '112', 'type': 'if_statement', 'children': ['113', '128']}, {'id': '113', 'type': 'boolean_operator', 'children': ['114', '121'], 'value': 'and'}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '118'], 'value': '<='}, {'id': '115', 'type': 'subscript', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'artf'}, {'id': '117', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '125'], 'value': '<='}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'artf'}, {'id': '127', 'type': 'string', 'children': [], 'value': "'end'"}; {'id': '128', 'type': 'block', 'children': ['129', '133', '137']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'reject'}; {'id': '132', 'type': 'True', 'children': []}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'new_seg'}; {'id': '136', 'type': 'False', 'children': []}, {'id': '137', 'type': 'break_statement', 'children': []}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'a_starts_in_s'}, {'id': '141', 'type': 'comparison_operator', 'children': ['142', '145', '148'], 'value': '<='}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'artf'}, {'id': '147', 'type': 'string', 'children': [], 'value': "'start'"}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'a_ends_in_s'}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '158', '161'], 'value': '<='}, {'id': '155', 'type': 'subscript', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '157', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'artf'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'end'"}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '163', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '164', 'type': 'if_statement', 'children': ['165', '169', '180']}, {'id': '165', 'type': 'boolean_operator', 'children': ['166', '167'], 'value': 'and'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'a_ends_in_s'}, {'id': '167', 'type': 'not_operator', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'a_starts_in_s'}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '173', 'type': 'expression_list', 'children': ['174', '177']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'artf'}; {'id': '176', 'type': 'string', 'children': [], 'value': "'end'"}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '179', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '180', 'type': 'elif_clause', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'a_starts_in_s'}; {'id': '182', 'type': 'block', 'children': ['183', '193', '210']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '186', 'type': 'expression_list', 'children': ['187', '190']}, {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '189', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '190', 'type': 'subscript', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'artf'}; {'id': '192', 'type': 'string', 'children': [], 'value': "'start'"}, {'id': '193', 'type': 'if_statement', 'children': ['194', '195', '204']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'a_ends_in_s'}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'new_seg'}, {'id': '199', 'type': 'expression_list', 'children': ['200', '203']}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'artf'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'end'"}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '204', 'type': 'else_clause', 'children': ['205']}, {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'assignment', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'new_seg'}, {'id': '209', 'type': 'False', 'children': []}; {'id': '210', 'type': 'break_statement', 'children': []}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'new_seg'}; {'id': '214', 'type': 'False', 'children': []}, {'id': '215', 'type': 'if_statement', 'children': ['216', '229']}; {'id': '216', 'type': 'boolean_operator', 'children': ['217', '220'], 'value': 'and'}, {'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': 'is'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'reject'}, {'id': '219', 'type': 'False', 'children': []}; {'id': '220', 'type': 'comparison_operator', 'children': ['221', '228'], 'value': '>='}, {'id': '221', 'type': 'binary_operator', 'children': ['222', '225'], 'value': '-'}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'seg'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '225', 'type': 'subscript', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '227', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'min_dur'}, {'id': '229', 'type': 'block', 'children': ['230']}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'new_times'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'seg'}, {'id': '237', 'type': 'return_statement', 'children': ['238']} | def remove_artf_evts(times, annot, chan=None, min_dur=0.1):
new_times = times
beg = times[0][0]
end = times[-1][-1]
chan = (chan, '') if chan else None
artefact = annot.get_events(name='Artefact', time=(beg, end), chan=chan,
qual='Good')
if artefact:
new_times = []
for seg in times:
reject = False
new_seg = True
while new_seg is not False:
if type(new_seg) is tuple:
seg = new_seg
end = seg[1]
for artf in artefact:
if artf['start'] <= seg[0] and seg[1] <= artf['end']:
reject = True
new_seg = False
break
a_starts_in_s = seg[0] <= artf['start'] <= seg[1]
a_ends_in_s = seg[0] <= artf['end'] <= seg[1]
if a_ends_in_s and not a_starts_in_s:
seg = artf['end'], seg[1]
elif a_starts_in_s:
seg = seg[0], artf['start']
if a_ends_in_s:
new_seg = artf['end'], end
else:
new_seg = False
break
new_seg = False
if reject is False and seg[1] - seg[0] >= min_dur:
new_times.append(seg)
return new_times |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_build_app_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'site'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '14', '51', '257', '267']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'app_dict'}, {'id': '13', 'type': 'dictionary', 'children': []}; {'id': '14', 'type': 'if_statement', 'children': ['15', '16', '43']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '20', 'type': 'dictionary_comprehension', 'children': ['21', '24', '35']}, {'id': '21', 'type': 'pair', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'm_a'}; {'id': '24', 'type': 'for_in_clause', 'children': ['25', '28']}, {'id': '25', 'type': 'pattern_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'm_a'}; {'id': '28', 'type': 'call', 'children': ['29', '34']}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'site'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_registry'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'if_clause', 'children': ['36']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '42'], 'value': '=='}, {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '_meta'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'app_label'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '43', 'type': 'else_clause', 'children': ['44']}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'site'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': '_registry'}, {'id': '51', 'type': 'for_statement', 'children': ['52', '55', '60']}; {'id': '52', 'type': 'pattern_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'model_admin'}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'models'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '59', 'type': 'argument_list', 'children': []}; {'id': '60', 'type': 'block', 'children': ['61', '69', '78', '83', '92', '102', '112', '136', '166', '196']}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'app_label'}; {'id': '64', 'type': 'attribute', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'app_label'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'has_module_perms'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'model_admin'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'has_module_permission'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '81']}, {'id': '79', 'type': 'not_operator', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'has_module_perms'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'continue_statement', 'children': []}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'perms'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'model_admin'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'get_model_perms'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '92', 'type': 'if_statement', 'children': ['93', '100']}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'not'}; {'id': '94', 'type': 'True', 'children': []}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'perms'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '99', 'type': 'argument_list', 'children': []}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'continue_statement', 'children': []}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '105', 'type': 'tuple', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'app_label'}, {'id': '107', 'type': 'attribute', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': '_meta'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'model_name'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'model_dict'}, {'id': '115', 'type': 'dictionary', 'children': ['116', '126', '133']}; {'id': '116', 'type': 'pair', 'children': ['117', '118']}, {'id': '117', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'capfirst'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'attribute', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': '_meta'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'verbose_name_plural'}; {'id': '126', 'type': 'pair', 'children': ['127', '128']}, {'id': '127', 'type': 'string', 'children': [], 'value': "'object_name'"}; {'id': '128', 'type': 'attribute', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'object_name'}, {'id': '133', 'type': 'pair', 'children': ['134', '135']}; {'id': '134', 'type': 'string', 'children': [], 'value': "'perms'"}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'perms'}; {'id': '136', 'type': 'if_statement', 'children': ['137', '143']}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'perms'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'string', 'children': [], 'value': "'change'"}, {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'try_statement', 'children': ['145', '162']}, {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '151']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'model_dict'}; {'id': '150', 'type': 'string', 'children': [], 'value': "'admin_url'"}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '153', 'type': 'argument_list', 'children': ['154', '157']}; {'id': '154', 'type': 'binary_operator', 'children': ['155', '156'], 'value': '%'}, {'id': '155', 'type': 'string', 'children': [], 'value': "'admin:%s_%s_changelist'"}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'current_app'}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'site'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '162', 'type': 'except_clause', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'NoReverseMatch'}; {'id': '164', 'type': 'block', 'children': ['165']}, {'id': '165', 'type': 'pass_statement', 'children': []}; {'id': '166', 'type': 'if_statement', 'children': ['167', '173']}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'perms'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'string', 'children': [], 'value': "'add'"}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'try_statement', 'children': ['175', '192']}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '181']}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'model_dict'}; {'id': '180', 'type': 'string', 'children': [], 'value': "'add_url'"}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '183', 'type': 'argument_list', 'children': ['184', '187']}; {'id': '184', 'type': 'binary_operator', 'children': ['185', '186'], 'value': '%'}, {'id': '185', 'type': 'string', 'children': [], 'value': "'admin:%s_%s_add'"}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'current_app'}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'site'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '192', 'type': 'except_clause', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'NoReverseMatch'}; {'id': '194', 'type': 'block', 'children': ['195']}, {'id': '195', 'type': 'pass_statement', 'children': []}; {'id': '196', 'type': 'if_statement', 'children': ['197', '200', '212']}, {'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': 'in'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'app_label'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'app_dict'}; {'id': '200', 'type': 'block', 'children': ['201']}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '210']}, {'id': '203', 'type': 'attribute', 'children': ['204', '209']}; {'id': '204', 'type': 'subscript', 'children': ['205', '208']}, {'id': '205', 'type': 'subscript', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'app_dict'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'app_label'}; {'id': '208', 'type': 'string', 'children': [], 'value': "'models'"}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'model_dict'}; {'id': '212', 'type': 'else_clause', 'children': ['213']}, {'id': '213', 'type': 'block', 'children': ['214']}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '219']}; {'id': '216', 'type': 'subscript', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'app_dict'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'app_label'}, {'id': '219', 'type': 'dictionary', 'children': ['220', '230', '233', '250', '253']}; {'id': '220', 'type': 'pair', 'children': ['221', '222']}, {'id': '221', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '222', 'type': 'attribute', 'children': ['223', '229']}, {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'apps'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'get_app_config'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'app_label'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'verbose_name'}; {'id': '230', 'type': 'pair', 'children': ['231', '232']}, {'id': '231', 'type': 'string', 'children': [], 'value': "'app_label'"}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'app_label'}, {'id': '233', 'type': 'pair', 'children': ['234', '235']}; {'id': '234', 'type': 'string', 'children': [], 'value': "'app_url'"}, {'id': '235', 'type': 'call', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'reverse'}, {'id': '237', 'type': 'argument_list', 'children': ['238', '239', '245']}; {'id': '238', 'type': 'string', 'children': [], 'value': "'admin:app_list'"}, {'id': '239', 'type': 'keyword_argument', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '241', 'type': 'dictionary', 'children': ['242']}; {'id': '242', 'type': 'pair', 'children': ['243', '244']}, {'id': '243', 'type': 'string', 'children': [], 'value': "'app_label'"}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'app_label'}, {'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'current_app'}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'site'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '250', 'type': 'pair', 'children': ['251', '252']}, {'id': '251', 'type': 'string', 'children': [], 'value': "'has_module_perms'"}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'has_module_perms'}, {'id': '253', 'type': 'pair', 'children': ['254', '255']}; {'id': '254', 'type': 'string', 'children': [], 'value': "'models'"}, {'id': '255', 'type': 'list', 'children': ['256'], 'value': '[model_dict]'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'model_dict'}, {'id': '257', 'type': 'if_statement', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '259', 'type': 'block', 'children': ['260']}; {'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': 'app_dict'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '267', 'type': 'return_statement', 'children': ['268']} | def _build_app_dict(site, request, label=None):
app_dict = {}
if label:
models = {
m: m_a for m, m_a in site._registry.items()
if m._meta.app_label == label
}
else:
models = site._registry
for model, model_admin in models.items():
app_label = model._meta.app_label
has_module_perms = model_admin.has_module_permission(request)
if not has_module_perms:
continue
perms = model_admin.get_model_perms(request)
if True not in perms.values():
continue
info = (app_label, model._meta.model_name)
model_dict = {
'name': capfirst(model._meta.verbose_name_plural),
'object_name': model._meta.object_name,
'perms': perms,
}
if perms.get('change'):
try:
model_dict['admin_url'] = reverse('admin:%s_%s_changelist' % info, current_app=site.name)
except NoReverseMatch:
pass
if perms.get('add'):
try:
model_dict['add_url'] = reverse('admin:%s_%s_add' % info, current_app=site.name)
except NoReverseMatch:
pass
if app_label in app_dict:
app_dict[app_label]['models'].append(model_dict)
else:
app_dict[app_label] = {
'name': apps.get_app_config(app_label).verbose_name,
'app_label': app_label,
'app_url': reverse(
'admin:app_list',
kwargs={'app_label': app_label},
current_app=site.name,
),
'has_module_perms': has_module_perms,
'models': [model_dict],
}
if label:
return app_dict.get(label)
return app_dict |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_app_list'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'site'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '38', '58']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'app_dict'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': '_build_app_dict'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'site'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'app_list'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '26']}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'app_dict'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '28', 'type': 'lambda', 'children': ['29', '31']}, {'id': '29', 'type': 'lambda_parameters', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '35', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'app_list'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '49']}; {'id': '44', 'type': 'attribute', 'children': ['45', '48']}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'models'"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '52', 'type': 'lambda', 'children': ['53', '55']}, {'id': '53', 'type': 'lambda_parameters', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '57', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '58', 'type': 'return_statement', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'app_list'} | def get_app_list(site, request):
app_dict = _build_app_dict(site, request)
app_list = sorted(app_dict.values(), key=lambda x: x['name'].lower())
for app in app_list:
app['models'].sort(key=lambda x: x['name'])
return app_list |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'ERROR', 'children': ['2']}; {'id': '2', 'type': 'function_definition', 'children': ['3', '4', '8']}, {'id': '3', 'type': 'function_name', 'children': [], 'value': 'format_query_results'}; {'id': '4', 'type': 'parameters', 'children': ['5', '6', '7']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'prop_nr'}; {'id': '8', 'type': 'block', 'children': ['9', '18', '114', '187', '248']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'prop_dt'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_prop_datatype'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'prop_nr'}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '21']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '21', 'type': 'block', 'children': ['22', '54']}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '30']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '24', 'type': 'set', 'children': ['25', '26', '27', '28', '29']}, {'id': '25', 'type': 'string', 'children': [], 'value': "'item'"}; {'id': '26', 'type': 'string', 'children': [], 'value': "'sid'"}, {'id': '27', 'type': 'string', 'children': [], 'value': "'pq'"}; {'id': '28', 'type': 'string', 'children': [], 'value': "'pr'"}, {'id': '29', 'type': 'string', 'children': [], 'value': "'ref'"}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'if_statement', 'children': ['32', '35']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'in'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'i'}, {'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': 'i'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '41', 'type': 'subscript', 'children': ['42', '52']}; {'id': '42', 'type': 'call', 'children': ['43', '50']}, {'id': '43', 'type': 'attribute', 'children': ['44', '49']}; {'id': '44', 'type': 'subscript', 'children': ['45', '48']}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'value'"}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '52', 'type': 'unary_operator', 'children': ['53'], 'value': '-'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '54', 'type': 'for_statement', 'children': ['55', '56', '60']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '56', 'type': 'set', 'children': ['57', '58', '59']}, {'id': '57', 'type': 'string', 'children': [], 'value': "'v'"}; {'id': '58', 'type': 'string', 'children': [], 'value': "'qval'"}, {'id': '59', 'type': 'string', 'children': [], 'value': "'rval'"}; {'id': '60', 'type': 'block', 'children': ['61']}, {'id': '61', 'type': 'if_statement', 'children': ['62', '65', '99']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'in'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '65', 'type': 'ERROR', 'children': ['66', '90']}; {'id': '66', 'type': 'if_statement', 'children': ['67', '78', '79']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '76', '77'], 'value': '=='}; {'id': '68', 'type': 'call', 'children': ['69', '74']}, {'id': '69', 'type': 'attribute', 'children': ['70', '73']}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'string', 'children': [], 'value': '"datatype"'}; {'id': '76', 'type': 'ERROR', 'children': []}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'http'}; {'id': '78', 'type': 'ERROR', 'children': []}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'binary_operator', 'children': ['82', '89'], 'value': '/'}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '88'], 'value': '/'}, {'id': '83', 'type': 'attribute', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'www'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'w3'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'org'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '2001'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'XMLSchema'}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '98'], 'value': 'in'}, {'id': '91', 'type': 'subscript', 'children': ['92', '97']}; {'id': '92', 'type': 'subscript', 'children': ['93', '96']}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'value'"}, {'id': '97', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'+-'"}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '107']}; {'id': '102', 'type': 'subscript', 'children': ['103', '106']}, {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'value'"}, {'id': '107', 'type': 'binary_operator', 'children': ['108', '109'], 'value': '+'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'+'"}, {'id': '109', 'type': 'subscript', 'children': ['110', '113']}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '113', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118']}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'in'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'v'"}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '118', 'type': 'block', 'children': ['119', '162']}, {'id': '119', 'type': 'if_statement', 'children': ['120', '131', '150']}; {'id': '120', 'type': 'boolean_operator', 'children': ['121', '128'], 'value': 'and'}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '127'], 'value': '=='}; {'id': '122', 'type': 'subscript', 'children': ['123', '126']}, {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '125', 'type': 'string', 'children': [], 'value': "'v'"}; {'id': '126', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '127', 'type': 'string', 'children': [], 'value': "'uri'"}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': '=='}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'prop_dt'}; {'id': '130', 'type': 'string', 'children': [], 'value': "'wikibase-item'"}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '137']}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '136', 'type': 'string', 'children': [], 'value': "'v'"}, {'id': '137', 'type': 'subscript', 'children': ['138', '148']}; {'id': '138', 'type': 'call', 'children': ['139', '146']}, {'id': '139', 'type': 'attribute', 'children': ['140', '145']}; {'id': '140', 'type': 'subscript', 'children': ['141', '144']}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '143', 'type': 'string', 'children': [], 'value': "'v'"}; {'id': '144', 'type': 'string', 'children': [], 'value': "'value'"}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '148', 'type': 'unary_operator', 'children': ['149'], 'value': '-'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '150', 'type': 'else_clause', 'children': ['151']}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '157']}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '156', 'type': 'string', 'children': [], 'value': "'v'"}, {'id': '157', 'type': 'subscript', 'children': ['158', '161']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'v'"}, {'id': '161', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '162', 'type': 'if_statement', 'children': ['163', '171']}, {'id': '163', 'type': 'comparison_operator', 'children': ['164', '170'], 'value': 'is'}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '169', 'type': 'string', 'children': [], 'value': "'v'"}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '183']}; {'id': '174', 'type': 'attribute', 'children': ['175', '182']}, {'id': '175', 'type': 'subscript', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'rev_lookup'}, {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '181', 'type': 'string', 'children': [], 'value': "'v'"}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '186', 'type': 'string', 'children': [], 'value': "'item'"}, {'id': '187', 'type': 'if_statement', 'children': ['188', '191']}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': 'in'}, {'id': '189', 'type': 'string', 'children': [], 'value': "'qval'"}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '191', 'type': 'block', 'children': ['192', '205']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'qual_prop_dt'}, {'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': 'get_prop_datatype'}, {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'prop_nr'}; {'id': '202', 'type': 'subscript', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '204', 'type': 'string', 'children': [], 'value': "'pq'"}, {'id': '205', 'type': 'if_statement', 'children': ['206', '217', '236']}; {'id': '206', 'type': 'boolean_operator', 'children': ['207', '214'], 'value': 'and'}, {'id': '207', 'type': 'comparison_operator', 'children': ['208', '213'], 'value': '=='}; {'id': '208', 'type': 'subscript', 'children': ['209', '212']}, {'id': '209', 'type': 'subscript', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '211', 'type': 'string', 'children': [], 'value': "'qval'"}; {'id': '212', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '213', 'type': 'string', 'children': [], 'value': "'uri'"}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': '=='}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'qual_prop_dt'}; {'id': '216', 'type': 'string', 'children': [], 'value': "'wikibase-item'"}, {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '223']}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '222', 'type': 'string', 'children': [], 'value': "'qval'"}, {'id': '223', 'type': 'subscript', 'children': ['224', '234']}; {'id': '224', 'type': 'call', 'children': ['225', '232']}, {'id': '225', 'type': 'attribute', 'children': ['226', '231']}; {'id': '226', 'type': 'subscript', 'children': ['227', '230']}, {'id': '227', 'type': 'subscript', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '229', 'type': 'string', 'children': [], 'value': "'qval'"}; {'id': '230', 'type': 'string', 'children': [], 'value': "'value'"}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '234', 'type': 'unary_operator', 'children': ['235'], 'value': '-'}, {'id': '235', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '236', 'type': 'else_clause', 'children': ['237']}, {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'assignment', 'children': ['240', '243']}; {'id': '240', 'type': 'subscript', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '242', 'type': 'string', 'children': [], 'value': "'qval'"}, {'id': '243', 'type': 'subscript', 'children': ['244', '247']}; {'id': '244', 'type': 'subscript', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '246', 'type': 'string', 'children': [], 'value': "'qval'"}, {'id': '247', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '248', 'type': 'if_statement', 'children': ['249', '252']}, {'id': '249', 'type': 'comparison_operator', 'children': ['250', '251'], 'value': 'in'}; {'id': '250', 'type': 'string', 'children': [], 'value': "'rval'"}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '252', 'type': 'block', 'children': ['253', '266']}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'ref_prop_dt'}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'get_prop_datatype'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'prop_nr'}, {'id': '263', 'type': 'subscript', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '265', 'type': 'string', 'children': [], 'value': "'pr'"}; {'id': '266', 'type': 'if_statement', 'children': ['267', '278', '297']}, {'id': '267', 'type': 'boolean_operator', 'children': ['268', '275'], 'value': 'and'}; {'id': '268', 'type': 'comparison_operator', 'children': ['269', '274'], 'value': '=='}, {'id': '269', 'type': 'subscript', 'children': ['270', '273']}; {'id': '270', 'type': 'subscript', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '272', 'type': 'string', 'children': [], 'value': "'rval'"}, {'id': '273', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '274', 'type': 'string', 'children': [], 'value': "'uri'"}, {'id': '275', 'type': 'comparison_operator', 'children': ['276', '277'], 'value': '=='}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'ref_prop_dt'}, {'id': '277', 'type': 'string', 'children': [], 'value': "'wikibase-item'"}; {'id': '278', 'type': 'block', 'children': ['279']}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '284']}, {'id': '281', 'type': 'subscript', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '283', 'type': 'string', 'children': [], 'value': "'rval'"}; {'id': '284', 'type': 'subscript', 'children': ['285', '295']}, {'id': '285', 'type': 'call', 'children': ['286', '293']}; {'id': '286', 'type': 'attribute', 'children': ['287', '292']}, {'id': '287', 'type': 'subscript', 'children': ['288', '291']}; {'id': '288', 'type': 'subscript', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '290', 'type': 'string', 'children': [], 'value': "'rval'"}, {'id': '291', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '295', 'type': 'unary_operator', 'children': ['296'], 'value': '-'}; {'id': '296', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '297', 'type': 'else_clause', 'children': ['298']}; {'id': '298', 'type': 'block', 'children': ['299']}, {'id': '299', 'type': 'expression_statement', 'children': ['300']}; {'id': '300', 'type': 'assignment', 'children': ['301', '304']}, {'id': '301', 'type': 'subscript', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '303', 'type': 'string', 'children': [], 'value': "'rval'"}; {'id': '304', 'type': 'subscript', 'children': ['305', '308']}, {'id': '305', 'type': 'subscript', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '307', 'type': 'string', 'children': [], 'value': "'rval'"} | def format_query_results(self, r, prop_nr):
prop_dt = self.get_prop_datatype(prop_nr)
for i in r:
for value in {'item', 'sid', 'pq', 'pr', 'ref'}:
if value in i:
i[value] = i[value]['value'].split('/')[-1]
for value in {'v', 'qval', 'rval'}:
if value in i:
if i[value].get("datatype") == 'http://www.w3.org/2001/XMLSchema
i[value]['value'][0] in '+-':
i[value]['value'] = '+' + i[value]['value']
if 'v' in i:
if i['v']['type'] == 'uri' and prop_dt == 'wikibase-item':
i['v'] = i['v']['value'].split('/')[-1]
else:
i['v'] = i['v']['value']
if type(i['v']) is not dict:
self.rev_lookup[i['v']].add(i['item'])
if 'qval' in i:
qual_prop_dt = self.get_prop_datatype(prop_nr=i['pq'])
if i['qval']['type'] == 'uri' and qual_prop_dt == 'wikibase-item':
i['qval'] = i['qval']['value'].split('/')[-1]
else:
i['qval'] = i['qval']['value']
if 'rval' in i:
ref_prop_dt = self.get_prop_datatype(prop_nr=i['pr'])
if i['rval']['type'] == 'uri' and ref_prop_dt == 'wikibase-item':
i['rval'] = i['rval']['value'].split('/')[-1]
else:
i['rval'] = i['rval']['value'] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'times'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'mint'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'maxt'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '12', '19', '153']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'string', 'children': [], 'value': "'''Repeat a parser between `mint` and `maxt` times. DO AS MUCH MATCH AS IT CAN.\n Return a list of values.'''"}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'maxt'}, {'id': '15', 'type': 'conditional_expression', 'children': ['16', '17', '18'], 'value': 'if'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'maxt'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'maxt'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'mint'}, {'id': '19', 'type': 'decorated_definition', 'children': ['20', '22']}; {'id': '20', 'type': 'decorator', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Parser'}; {'id': '22', 'type': 'function_definition', 'children': ['23', '24', '27']}, {'id': '23', 'type': 'function_name', 'children': [], 'value': 'times_parser'}; {'id': '24', 'type': 'parameters', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '27', 'type': 'block', 'children': ['28', '44', '151']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '34']}; {'id': '30', 'type': 'pattern_list', 'children': ['31', '32', '33']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'cnt'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '34', 'type': 'expression_list', 'children': ['35', '36', '43']}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'Value'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '42', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'while_statement', 'children': ['45', '48']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '<'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'maxt'}; {'id': '48', 'type': 'block', 'children': ['49', '57', '106', '112']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '61', '94']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '61', 'type': 'block', 'children': ['62', '82']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'aggregate'}, {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'Value'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '78', 'type': 'list', 'children': ['79'], 'value': '[res.value]'}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '87']}; {'id': '84', 'type': 'pattern_list', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '87', 'type': 'expression_list', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '+'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '94', 'type': 'else_clause', 'children': ['95']}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'if_statement', 'children': ['97', '100', '102']}, {'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': '>='}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'mint'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'break_statement', 'children': []}; {'id': '102', 'type': 'else_clause', 'children': ['103']}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'return_statement', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '110']}, {'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': '>='}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'maxt'}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'break_statement', 'children': []}; {'id': '112', 'type': 'if_statement', 'children': ['113', '119']}, {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': '>='}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'if_statement', 'children': ['121', '124', '126']}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': '>='}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'mint'}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'break_statement', 'children': []}; {'id': '126', 'type': 'else_clause', 'children': ['127']}, {'id': '127', 'type': 'block', 'children': ['128', '136']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '136', 'type': 'if_statement', 'children': ['137', '142']}, {'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': '!='}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'return_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'Value'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'failure'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '150', 'type': 'string', 'children': [], 'value': '"already meets the end, no enough text"'}, {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '153', 'type': 'return_statement', 'children': ['154']} | def times(p, mint, maxt=None):
'''Repeat a parser between `mint` and `maxt` times. DO AS MUCH MATCH AS IT CAN.
Return a list of values.'''
maxt = maxt if maxt else mint
@Parser
def times_parser(text, index):
cnt, values, res = 0, Value.success(index, []), None
while cnt < maxt:
res = p(text, index)
if res.status:
values = values.aggregate(
Value.success(res.index, [res.value]))
index, cnt = res.index, cnt + 1
else:
if cnt >= mint:
break
else:
return res
if cnt >= maxt:
break
if index >= len(text):
if cnt >= mint:
break
else:
r = p(text, index)
if index != r.index:
return Value.failure(index, "already meets the end, no enough text")
return values
return times_parser |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'separated'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'mint'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'maxt'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '16', '23', '212']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'string', 'children': [], 'value': "'''Repeat a parser `p` separated by `s` between `mint` and `maxt` times.\n When `end` is None, a trailing separator is optional.\n When `end` is True, a trailing separator is required.\n When `end` is False, a trailing separator is not allowed.\n MATCHES AS MUCH AS POSSIBLE.\n Return list of values returned by `p`.'''"}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'maxt'}, {'id': '19', 'type': 'conditional_expression', 'children': ['20', '21', '22'], 'value': 'if'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'maxt'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'maxt'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'mint'}, {'id': '23', 'type': 'decorated_definition', 'children': ['24', '26']}; {'id': '24', 'type': 'decorator', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Parser'}; {'id': '26', 'type': 'function_definition', 'children': ['27', '28', '31']}, {'id': '27', 'type': 'function_name', 'children': [], 'value': 'sep_parser'}; {'id': '28', 'type': 'parameters', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '31', 'type': 'block', 'children': ['32', '48', '210']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '38']}; {'id': '34', 'type': 'pattern_list', 'children': ['35', '36', '37']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'cnt'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '38', 'type': 'expression_list', 'children': ['39', '40', '47']}, {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'Value'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '46', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '47', 'type': 'None', 'children': []}; {'id': '48', 'type': 'while_statement', 'children': ['49', '52']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': '<'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'maxt'}; {'id': '52', 'type': 'block', 'children': ['53', '107', '115', '162', '204']}, {'id': '53', 'type': 'if_statement', 'children': ['54', '63']}; {'id': '54', 'type': 'boolean_operator', 'children': ['55', '60'], 'value': 'and'}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'in'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '57', 'type': 'list', 'children': ['58', '59'], 'value': '[False, None]'}; {'id': '58', 'type': 'False', 'children': []}, {'id': '59', 'type': 'None', 'children': []}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '>'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'cnt'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '63', 'type': 'block', 'children': ['64', '72']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'sep'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '76', '97', '104']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '82']}, {'id': '79', 'type': 'pattern_list', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '82', 'type': 'expression_list', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'Value'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '97', 'type': 'elif_clause', 'children': ['98', '101']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': '<'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'cnt'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'mint'}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'return_statement', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '104', 'type': 'else_clause', 'children': ['105']}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'break_statement', 'children': []}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '115', 'type': 'if_statement', 'children': ['116', '119', '152', '158']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '119', 'type': 'block', 'children': ['120', '140']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'aggregate'}, {'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': 'Value'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '136', 'type': 'list', 'children': ['137'], 'value': '[res.value]'}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '145']}; {'id': '142', 'type': 'pattern_list', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '145', 'type': 'expression_list', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '+'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '152', 'type': 'elif_clause', 'children': ['153', '156']}, {'id': '153', 'type': 'comparison_operator', 'children': ['154', '155'], 'value': '>='}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'mint'}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'break_statement', 'children': []}; {'id': '158', 'type': 'else_clause', 'children': ['159']}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'return_statement', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '162', 'type': 'if_statement', 'children': ['163', '166']}, {'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': 'is'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '165', 'type': 'True', 'children': []}; {'id': '166', 'type': 'block', 'children': ['167', '175']}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '170', 'type': 'call', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'sep'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '175', 'type': 'if_statement', 'children': ['176', '179', '200']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '185']}; {'id': '182', 'type': 'pattern_list', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '185', 'type': 'expression_list', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'Value'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'success'}, {'id': '193', 'type': 'argument_list', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '200', 'type': 'else_clause', 'children': ['201']}, {'id': '201', 'type': 'block', 'children': ['202']}; {'id': '202', 'type': 'return_statement', 'children': ['203']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '204', 'type': 'if_statement', 'children': ['205', '208']}, {'id': '205', 'type': 'comparison_operator', 'children': ['206', '207'], 'value': '>='}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'cnt'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'maxt'}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'break_statement', 'children': []}; {'id': '210', 'type': 'return_statement', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '212', 'type': 'return_statement', 'children': ['213']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'sep_parser'} | def separated(p, sep, mint, maxt=None, end=None):
'''Repeat a parser `p` separated by `s` between `mint` and `maxt` times.
When `end` is None, a trailing separator is optional.
When `end` is True, a trailing separator is required.
When `end` is False, a trailing separator is not allowed.
MATCHES AS MUCH AS POSSIBLE.
Return list of values returned by `p`.'''
maxt = maxt if maxt else mint
@Parser
def sep_parser(text, index):
cnt, values, res = 0, Value.success(index, []), None
while cnt < maxt:
if end in [False, None] and cnt > 0:
res = sep(text, index)
if res.status:
index, values = res.index, Value.success(
res.index, values.value)
elif cnt < mint:
return res
else:
break
res = p(text, index)
if res.status:
values = values.aggregate(
Value.success(res.index, [res.value]))
index, cnt = res.index, cnt + 1
elif cnt >= mint:
break
else:
return res
if end is True:
res = sep(text, index)
if res.status:
index, values = res.index, Value.success(
res.index, values.value)
else:
return res
if cnt >= maxt:
break
return values
return sep_parser |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'route'}, {'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', '55', '187', '192']}, {'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']}; {'id': '8', 'type': 'function_name', 'children': [], 'value': '_validate_route'}, {'id': '9', 'type': 'parameters', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'route'}, {'id': '11', 'type': 'block', 'children': ['12', '29']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '21']}, {'id': '13', 'type': 'not_operator', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'route'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'raise_statement', 'children': ['23']}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '%'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'%s must be a string'"}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'route'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '44']}; {'id': '30', 'type': 'boolean_operator', 'children': ['31', '36'], 'value': 'or'}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'in'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'route'}, {'id': '33', 'type': 'tuple', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '35', 'type': 'string', 'children': [], 'value': "'..'"}; {'id': '36', 'type': 'not_operator', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'^[0-9a-zA-Z-_$\\(\\)\\.~!,;:*+@=]+$'"}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'route'}; {'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': 'binary_operator', 'children': ['50', '54'], 'value': '%'}; {'id': '50', 'type': 'concatenated_string', 'children': ['51', '52', '53']}, {'id': '51', 'type': 'string', 'children': [], 'value': "'%s must be a valid path segment. Keep in mind '"}; {'id': '52', 'type': 'string', 'children': [], 'value': "'that path segments should not contain path separators '"}, {'id': '53', 'type': 'string', 'children': [], 'value': "'(e.g., /) '"}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'route'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '62', '126', '178']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '61'], 'value': '=='}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '62', 'type': 'block', 'children': ['63', '69', '81', '95', '105']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '68']}, {'id': '65', 'type': 'pattern_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'route'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '74']}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ismethod'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': '__func__'}, {'id': '81', 'type': 'if_statement', 'children': ['82', '87']}; {'id': '82', 'type': 'not_operator', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'iscontroller'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'handler'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'raise_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'binary_operator', 'children': ['93', '94'], 'value': '%'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'%s must be a callable decorated with @pecan.expose'"}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'handler'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '101']}, {'id': '97', 'type': 'pattern_list', 'children': ['98', '99', '100']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '101', 'type': 'expression_list', 'children': ['102', '103', '104']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'handler'}, {'id': '103', 'type': 'string', 'children': [], 'value': "'custom_route'"}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'route'}, {'id': '105', 'type': 'if_statement', 'children': ['106', '114']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '110'], 'value': 'in'}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'handler'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '110', 'type': 'tuple', 'children': ['111', '112', '113']}, {'id': '111', 'type': 'string', 'children': [], 'value': "'_lookup'"}; {'id': '112', 'type': 'string', 'children': [], 'value': "'_default'"}, {'id': '113', 'type': 'string', 'children': [], 'value': "'_route'"}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'raise_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '123'], 'value': '%'}; {'id': '120', 'type': 'concatenated_string', 'children': ['121', '122']}, {'id': '121', 'type': 'string', 'children': [], 'value': "'%s is a special method in pecan and cannot be used in '"}; {'id': '122', 'type': 'string', 'children': [], 'value': "'combination with custom path segments.'"}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'handler'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '126', 'type': 'elif_clause', 'children': ['127', '133']}, {'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': 'args'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '133', 'type': 'block', 'children': ['134', '141', '148']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '140']}; {'id': '136', 'type': 'pattern_list', 'children': ['137', '138', '139']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'route'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '147']}, {'id': '143', 'type': 'pattern_list', 'children': ['144', '145', '146']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '148', 'type': 'if_statement', 'children': ['149', '154']}, {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '151', 'type': 'argument_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'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': 'RuntimeError'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'parenthesized_expression', 'children': ['160'], 'value': '()'}; {'id': '160', 'type': 'binary_operator', 'children': ['161', '164'], 'value': '%'}, {'id': '161', 'type': 'concatenated_string', 'children': ['162', '163']}; {'id': '162', 'type': 'string', 'children': [], 'value': '"%(module)s.%(class)s already has an "'}, {'id': '163', 'type': 'string', 'children': [], 'value': '"existing attribute named \\"%(route)s\\"."'}; {'id': '164', 'type': 'dictionary', 'children': ['165', '170', '175']}, {'id': '165', 'type': 'pair', 'children': ['166', '167']}; {'id': '166', 'type': 'string', 'children': [], 'value': "'module'"}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': '__module__'}; {'id': '170', 'type': 'pair', 'children': ['171', '172']}, {'id': '171', 'type': 'string', 'children': [], 'value': "'class'"}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '175', 'type': 'pair', 'children': ['176', '177']}; {'id': '176', 'type': 'string', 'children': [], 'value': "'route'"}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '178', 'type': 'else_clause', 'children': ['179']}, {'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': 'TypeError'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'concatenated_string', 'children': ['185', '186']}, {'id': '185', 'type': 'string', 'children': [], 'value': "'pecan.route should be called in the format '"}; {'id': '186', 'type': 'string', 'children': [], 'value': '\'route(ParentController, "path-segment", SubController())\''}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': '_validate_route'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'route'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '195', 'type': 'argument_list', 'children': ['196', '197', '198']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'attr'} | def route(*args):
def _validate_route(route):
if not isinstance(route, six.string_types):
raise TypeError('%s must be a string' % route)
if route in ('.', '..') or not re.match(
'^[0-9a-zA-Z-_$\(\)\.~!,;:*+@=]+$', route
):
raise ValueError(
'%s must be a valid path segment. Keep in mind '
'that path segments should not contain path separators '
'(e.g., /) ' % route
)
if len(args) == 2:
route, handler = args
if ismethod(handler):
handler = handler.__func__
if not iscontroller(handler):
raise TypeError(
'%s must be a callable decorated with @pecan.expose' % handler
)
obj, attr, value = handler, 'custom_route', route
if handler.__name__ in ('_lookup', '_default', '_route'):
raise ValueError(
'%s is a special method in pecan and cannot be used in '
'combination with custom path segments.' % handler.__name__
)
elif len(args) == 3:
_, route, handler = args
obj, attr, value = args
if hasattr(obj, attr):
raise RuntimeError(
(
"%(module)s.%(class)s already has an "
"existing attribute named \"%(route)s\"." % {
'module': obj.__module__,
'class': obj.__name__,
'route': attr
}
),
)
else:
raise TypeError(
'pecan.route should be called in the format '
'route(ParentController, "path-segment", SubController())'
)
_validate_route(route)
setattr(obj, attr, value) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_object'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'notfound_handlers'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '8', 'type': 'block', 'children': ['9', '11', '15']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'string', 'children': [], 'value': "'''\n 'Walks' the url path in search of an action for which a controller is\n implemented and returns that controller object along with what's left\n of the remainder.\n '''"}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'prev_obj'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'while_statement', 'children': ['16', '17']}; {'id': '16', 'type': 'True', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18', '25', '45', '50', '83', '89', '153', '162', '178', '187', '203', '212', '286', '292', '296', '300', '304', '322']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'raise_statement', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'PecanNotFound'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '30']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'iscontroller'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'if_statement', 'children': ['32', '40']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '39'], 'value': 'is'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37', '38']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '37', 'type': 'string', 'children': [], 'value': "'custom_route'"}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'expression_list', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '_detect_custom_path_segments'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '50', 'type': 'if_statement', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '52', 'type': 'block', 'children': ['53', '68']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'custom_route'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '__custom_routes__'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'tuple', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'custom_route'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'return_statement', 'children': ['72']}; {'id': '72', 'type': 'expression_list', 'children': ['73', '78']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'custom_route'}; {'id': '78', 'type': 'subscript', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '80', 'type': 'slice', 'children': ['81', '82']}, {'id': '81', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '82', 'type': 'colon', 'children': []}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'cross_boundary'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'prev_obj'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '89', 'type': 'try_statement', 'children': ['90', '129']}; {'id': '90', 'type': 'block', 'children': ['91', '105']}, {'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': 'next_obj'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '96', 'type': 'expression_list', 'children': ['97', '100']}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '102', 'type': 'slice', 'children': ['103', '104']}, {'id': '103', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '104', 'type': 'colon', 'children': []}, {'id': '105', 'type': 'if_statement', 'children': ['106', '109']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': '=='}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'next_obj'}; {'id': '108', 'type': 'string', 'children': [], 'value': "''"}, {'id': '109', 'type': 'block', 'children': ['110', '119']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '117', '118']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '117', 'type': 'string', 'children': [], 'value': "'index'"}; {'id': '118', 'type': 'None', 'children': []}, {'id': '119', 'type': 'if_statement', 'children': ['120', '124']}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'iscontroller'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'return_statement', 'children': ['126']}; {'id': '126', 'type': 'expression_list', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'rest'}, {'id': '129', 'type': 'except_clause', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'IndexError'}, {'id': '131', 'type': 'block', 'children': ['132', '141']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '139', '140']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '139', 'type': 'string', 'children': [], 'value': "'index'"}; {'id': '140', 'type': 'None', 'children': []}, {'id': '141', 'type': 'if_statement', 'children': ['142', '146']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'iscontroller'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'raise_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'NonCanonicalPath'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '152', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '160', '161']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'_default'"}, {'id': '161', 'type': 'None', 'children': []}; {'id': '162', 'type': 'if_statement', 'children': ['163', '167']}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'iscontroller'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'notfound_handlers'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'tuple', 'children': ['175', '176', '177']}, {'id': '175', 'type': 'string', 'children': [], 'value': "'_default'"}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'lookup'}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '183', 'type': 'argument_list', 'children': ['184', '185', '186']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '185', 'type': 'string', 'children': [], 'value': "'_lookup'"}; {'id': '186', 'type': 'None', 'children': []}, {'id': '187', 'type': 'if_statement', 'children': ['188', '192']}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'iscontroller'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'lookup'}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'notfound_handlers'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}, {'id': '199', 'type': 'tuple', 'children': ['200', '201', '202']}; {'id': '200', 'type': 'string', 'children': [], 'value': "'_lookup'"}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'lookup'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'route'}; {'id': '206', 'type': 'call', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '210', '211']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '210', 'type': 'string', 'children': [], 'value': "'_route'"}, {'id': '211', 'type': 'None', 'children': []}; {'id': '212', 'type': 'if_statement', 'children': ['213', '217']}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'iscontroller'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'route'}, {'id': '217', 'type': 'block', 'children': ['218', '276', '282']}; {'id': '218', 'type': 'if_statement', 'children': ['219', '230', '264']}, {'id': '219', 'type': 'comparison_operator', 'children': ['220', '229'], 'value': '=='}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'attribute', 'children': ['224', '228']}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'getargspec'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'route'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '229', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '230', 'type': 'block', 'children': ['231', '255']}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'warnings'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '236', 'type': 'argument_list', 'children': ['237', '254']}, {'id': '237', 'type': 'parenthesized_expression', 'children': ['238'], 'value': '()'}; {'id': '238', 'type': 'binary_operator', 'children': ['239', '243'], 'value': '%'}, {'id': '239', 'type': 'concatenated_string', 'children': ['240', '241', '242']}; {'id': '240', 'type': 'string', 'children': [], 'value': '"The function signature for %s.%s._route is changing "'}, {'id': '241', 'type': 'string', 'children': [], 'value': '"in the next version of pecan.\\nPlease update to: "'}; {'id': '242', 'type': 'string', 'children': [], 'value': '"`def _route(self, args, request)`."'}, {'id': '243', 'type': 'tuple', 'children': ['244', '249']}; {'id': '244', 'type': 'attribute', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': '__module__'}, {'id': '249', 'type': 'attribute', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'DeprecationWarning'}, {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '260']}, {'id': '257', 'type': 'pattern_list', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'next_obj'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'next_remainder'}; {'id': '260', 'type': 'call', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'route'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '264', 'type': 'else_clause', 'children': ['265']}, {'id': '265', 'type': 'block', 'children': ['266']}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'assignment', 'children': ['268', '271']}; {'id': '268', 'type': 'pattern_list', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'next_obj'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'next_remainder'}, {'id': '271', 'type': 'call', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'route'}, {'id': '273', 'type': 'argument_list', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'call', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'cross_boundary'}, {'id': '279', 'type': 'argument_list', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'route'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'next_obj'}; {'id': '282', 'type': 'return_statement', 'children': ['283']}, {'id': '283', 'type': 'expression_list', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'next_obj'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'next_remainder'}; {'id': '286', 'type': 'if_statement', 'children': ['287', '289']}, {'id': '287', 'type': 'not_operator', 'children': ['288']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '289', 'type': 'block', 'children': ['290']}; {'id': '290', 'type': 'raise_statement', 'children': ['291']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'PecanNotFound'}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'prev_remainder'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}, {'id': '297', 'type': 'assignment', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'prev_obj'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '304', 'type': 'try_statement', 'children': ['305', '315']}, {'id': '305', 'type': 'block', 'children': ['306']}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'assignment', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '311', 'type': 'argument_list', 'children': ['312', '313', '314']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'next_obj'}; {'id': '314', 'type': 'None', 'children': []}, {'id': '315', 'type': 'except_clause', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'UnicodeEncodeError'}, {'id': '317', 'type': 'block', 'children': ['318']}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}, {'id': '319', 'type': 'assignment', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '321', 'type': 'None', 'children': []}; {'id': '322', 'type': 'if_statement', 'children': ['323', '334']}, {'id': '323', 'type': 'boolean_operator', 'children': ['324', '329'], 'value': 'and'}; {'id': '324', 'type': 'boolean_operator', 'children': ['325', '327'], 'value': 'and'}, {'id': '325', 'type': 'not_operator', 'children': ['326']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '327', 'type': 'not_operator', 'children': ['328']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'notfound_handlers'}, {'id': '329', 'type': 'call', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '331', 'type': 'argument_list', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'prev_obj'}, {'id': '333', 'type': 'string', 'children': [], 'value': "'index'"}; {'id': '334', 'type': 'block', 'children': ['335']}, {'id': '335', 'type': 'if_statement', 'children': ['336', '352']}; {'id': '336', 'type': 'comparison_operator', 'children': ['337', '340'], 'value': 'in'}, {'id': '337', 'type': 'attribute', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '340', 'type': 'call', 'children': ['341', '349']}, {'id': '341', 'type': 'attribute', 'children': ['342', '348']}; {'id': '342', 'type': 'call', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': '_cfg'}; {'id': '344', 'type': 'argument_list', 'children': ['345']}, {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'prev_obj'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '349', 'type': 'argument_list', 'children': ['350', '351']}; {'id': '350', 'type': 'string', 'children': [], 'value': "'generic_handlers'"}, {'id': '351', 'type': 'dictionary', 'children': []}; {'id': '352', 'type': 'block', 'children': ['353']}, {'id': '353', 'type': 'return_statement', 'children': ['354']}; {'id': '354', 'type': 'expression_list', 'children': ['355', '358']}, {'id': '355', 'type': 'attribute', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'prev_obj'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'index'} | def find_object(obj, remainder, notfound_handlers, request):
'''
'Walks' the url path in search of an action for which a controller is
implemented and returns that controller object along with what's left
of the remainder.
'''
prev_obj = None
while True:
if obj is None:
raise PecanNotFound
if iscontroller(obj):
if getattr(obj, 'custom_route', None) is None:
return obj, remainder
_detect_custom_path_segments(obj)
if remainder:
custom_route = __custom_routes__.get((obj.__class__, remainder[0]))
if custom_route:
return getattr(obj, custom_route), remainder[1:]
cross_boundary(prev_obj, obj)
try:
next_obj, rest = remainder[0], remainder[1:]
if next_obj == '':
index = getattr(obj, 'index', None)
if iscontroller(index):
return index, rest
except IndexError:
index = getattr(obj, 'index', None)
if iscontroller(index):
raise NonCanonicalPath(index, [])
default = getattr(obj, '_default', None)
if iscontroller(default):
notfound_handlers.append(('_default', default, remainder))
lookup = getattr(obj, '_lookup', None)
if iscontroller(lookup):
notfound_handlers.append(('_lookup', lookup, remainder))
route = getattr(obj, '_route', None)
if iscontroller(route):
if len(getargspec(route).args) == 2:
warnings.warn(
(
"The function signature for %s.%s._route is changing "
"in the next version of pecan.\nPlease update to: "
"`def _route(self, args, request)`." % (
obj.__class__.__module__,
obj.__class__.__name__
)
),
DeprecationWarning
)
next_obj, next_remainder = route(remainder)
else:
next_obj, next_remainder = route(remainder, request)
cross_boundary(route, next_obj)
return next_obj, next_remainder
if not remainder:
raise PecanNotFound
prev_remainder = remainder
prev_obj = obj
remainder = rest
try:
obj = getattr(obj, next_obj, None)
except UnicodeEncodeError:
obj = None
if not obj and not notfound_handlers and hasattr(prev_obj, 'index'):
if request.method in _cfg(prev_obj.index).get('generic_handlers',
{}):
return prev_obj.index, prev_remainder |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_app'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '7', 'type': 'block', 'children': ['8', '10', '20', '30', '91', '100', '110', '120', '137', '152', '163', '173', '250', '274']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': '\'\'\'\n Utility for creating the Pecan application object. This function should\n generally be called from the ``setup_app`` function in your project\'s\n ``app.py`` file.\n :param root: A string representing a root controller object (e.g.,\n "myapp.controller.root.RootController")\n :param static_root: The relative path to a directory containing static\n files. Serving static files is only enabled when\n debug mode is set.\n :param debug: A flag to enable debug mode. This enables the debug\n middleware and serving static files.\n :param wrap_app: A function or middleware class to wrap the Pecan app.\n This must either be a wsgi middleware class or a\n function that returns a wsgi application. This wrapper\n is applied first before wrapping the application in\n other middlewares such as Pecan\'s debug middleware.\n This should be used if you want to use middleware to\n perform authentication or intercept all requests before\n they are routed to the root controller.\n :param logging: A dictionary used to configure logging. This uses\n ``logging.config.dictConfig``.\n All other keyword arguments are passed in to the Pecan app constructor.\n :returns: a ``Pecan`` object.\n \'\'\''}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'logging'"}, {'id': '19', 'type': 'dictionary', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'debug'"}, {'id': '29', 'type': 'False', 'children': []}; {'id': '30', 'type': 'if_statement', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '32', 'type': 'block', 'children': ['33', '60', '75', '86']}, {'id': '33', 'type': 'if_statement', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'try_statement', 'children': ['37', '56']}, {'id': '37', 'type': 'block', 'children': ['38', '43', '48']}; {'id': '38', 'type': 'import_from_statement', 'children': ['39', '41']}, {'id': '39', 'type': 'dotted_name', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '41', 'type': 'dotted_name', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'captureWarnings'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'captureWarnings'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'True', 'children': []}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'simplefilter'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'string', 'children': [], 'value': '"default"'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'DeprecationWarning'}; {'id': '56', 'type': 'except_clause', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ImportError'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'pass_statement', 'children': []}; {'id': '60', 'type': 'if_statement', 'children': ['61', '66']}, {'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': 'logging'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'Config'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'to_dict'}; {'id': '74', 'type': 'argument_list', 'children': []}, {'id': '75', 'type': 'if_statement', 'children': ['76', '79']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'not'}, {'id': '77', 'type': 'string', 'children': [], 'value': "'version'"}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '85']}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'version'"}, {'id': '85', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'load_logging_config'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'Pecan'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '98', 'type': 'dictionary_splat', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'wrap_app'}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'wrap_app'"}, {'id': '109', 'type': 'None', 'children': []}; {'id': '110', 'type': 'if_statement', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'wrap_app'}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'wrap_app'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '129']}; {'id': '128', 'type': 'string', 'children': [], 'value': "'errors'"}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '135', '136']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'errors'"}; {'id': '136', 'type': 'dictionary', 'children': []}, {'id': '137', 'type': 'if_statement', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'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': 'app'}, {'id': '143', 'type': 'call', 'children': ['144', '149']}; {'id': '144', 'type': 'attribute', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'middleware'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'errordocument'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'ErrorDocumentMiddleware'}, {'id': '149', 'type': 'argument_list', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '155', 'type': 'call', 'children': ['156', '161']}; {'id': '156', 'type': 'attribute', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'middleware'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'recursive'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'RecursiveMiddleware'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'static_root'}; {'id': '166', 'type': 'call', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '172']}, {'id': '171', 'type': 'string', 'children': [], 'value': "'static_root'"}; {'id': '172', 'type': 'None', 'children': []}, {'id': '173', 'type': 'if_statement', 'children': ['174', '175', '239']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '175', 'type': 'block', 'children': ['176', '185', '215', '224']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'debug_kwargs'}, {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '181', 'type': 'argument_list', 'children': ['182', '183', '184']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '183', 'type': 'string', 'children': [], 'value': "'debug'"}; {'id': '184', 'type': 'dictionary', 'children': []}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '196']}, {'id': '187', 'type': 'attribute', 'children': ['188', '195']}; {'id': '188', 'type': 'call', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'debug_kwargs'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194']}, {'id': '193', 'type': 'string', 'children': [], 'value': "'context_injectors'"}; {'id': '194', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'lambda', 'children': ['198', '200']}; {'id': '198', 'type': 'lambda_parameters', 'children': ['199']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '200', 'type': 'dictionary', 'children': ['201']}, {'id': '201', 'type': 'pair', 'children': ['202', '203']}; {'id': '202', 'type': 'string', 'children': [], 'value': "'request'"}, {'id': '203', 'type': 'call', 'children': ['204', '213']}; {'id': '204', 'type': 'attribute', 'children': ['205', '212']}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '209', 'type': 'argument_list', 'children': ['210', '211']}; {'id': '210', 'type': 'string', 'children': [], 'value': "'pecan.locals'"}, {'id': '211', 'type': 'dictionary', 'children': []}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'string', 'children': [], 'value': "'request'"}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '218', 'type': 'call', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'DebugMiddleware'}; {'id': '220', 'type': 'argument_list', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '222', 'type': 'dictionary_splat', 'children': ['223']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'debug_kwargs'}; {'id': '224', 'type': 'if_statement', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'static_root'}; {'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': 'app'}; {'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': 'middleware'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'static'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'StaticFileMiddleware'}; {'id': '236', 'type': 'argument_list', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'static_root'}, {'id': '239', 'type': 'elif_clause', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'static_root'}, {'id': '241', 'type': 'block', 'children': ['242']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'call', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '247', 'type': 'argument_list', 'children': ['248', '249']}; {'id': '248', 'type': 'string', 'children': [], 'value': '"`static_root` is only used when `debug` is True, ignoring"'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'RuntimeWarning'}; {'id': '250', 'type': 'if_statement', 'children': ['251', '256']}, {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '253', 'type': 'argument_list', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '255', 'type': 'string', 'children': [], 'value': "'requestviewer'"}; {'id': '256', 'type': 'block', 'children': ['257']}, {'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': 'warnings'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '262', 'type': 'argument_list', 'children': ['263', '273']}, {'id': '263', 'type': 'call', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}, {'id': '265', 'type': 'string', 'children': [], 'value': "''"}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'list', 'children': ['269', '270', '271', '272'], 'value': '[\n "`pecan.conf.requestviewer` is deprecated. To apply the ",\n "`RequestViewerHook` to your application, add it to ",\n "`pecan.conf.app.hooks` or manually in your project\'s `app.py` ",\n "file."]'}, {'id': '269', 'type': 'string', 'children': [], 'value': '"`pecan.conf.requestviewer` is deprecated. To apply the "'}; {'id': '270', 'type': 'string', 'children': [], 'value': '"`RequestViewerHook` to your application, add it to "'}, {'id': '271', 'type': 'string', 'children': [], 'value': '"`pecan.conf.app.hooks` or manually in your project\'s `app.py` "'}; {'id': '272', 'type': 'string', 'children': [], 'value': '"file."'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'DeprecationWarning'}; {'id': '274', 'type': 'return_statement', 'children': ['275']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'app'} | def make_app(root, **kw):
'''
Utility for creating the Pecan application object. This function should
generally be called from the ``setup_app`` function in your project's
``app.py`` file.
:param root: A string representing a root controller object (e.g.,
"myapp.controller.root.RootController")
:param static_root: The relative path to a directory containing static
files. Serving static files is only enabled when
debug mode is set.
:param debug: A flag to enable debug mode. This enables the debug
middleware and serving static files.
:param wrap_app: A function or middleware class to wrap the Pecan app.
This must either be a wsgi middleware class or a
function that returns a wsgi application. This wrapper
is applied first before wrapping the application in
other middlewares such as Pecan's debug middleware.
This should be used if you want to use middleware to
perform authentication or intercept all requests before
they are routed to the root controller.
:param logging: A dictionary used to configure logging. This uses
``logging.config.dictConfig``.
All other keyword arguments are passed in to the Pecan app constructor.
:returns: a ``Pecan`` object.
'''
logging = kw.get('logging', {})
debug = kw.get('debug', False)
if logging:
if debug:
try:
from logging import captureWarnings
captureWarnings(True)
warnings.simplefilter("default", DeprecationWarning)
except ImportError:
pass
if isinstance(logging, Config):
logging = logging.to_dict()
if 'version' not in logging:
logging['version'] = 1
load_logging_config(logging)
app = Pecan(root, **kw)
wrap_app = kw.get('wrap_app', None)
if wrap_app:
app = wrap_app(app)
errors = kw.get('errors', getattr(conf.app, 'errors', {}))
if errors:
app = middleware.errordocument.ErrorDocumentMiddleware(app, errors)
app = middleware.recursive.RecursiveMiddleware(app)
static_root = kw.get('static_root', None)
if debug:
debug_kwargs = getattr(conf, 'debug', {})
debug_kwargs.setdefault('context_injectors', []).append(
lambda environ: {
'request': environ.get('pecan.locals', {}).get('request')
}
)
app = DebugMiddleware(
app,
**debug_kwargs
)
if static_root:
app = middleware.static.StaticFileMiddleware(app, static_root)
elif static_root:
warnings.warn(
"`static_root` is only used when `debug` is True, ignoring",
RuntimeWarning
)
if hasattr(conf, 'requestviewer'):
warnings.warn(''.join([
"`pecan.conf.requestviewer` is deprecated. To apply the ",
"`RequestViewerHook` to your application, add it to ",
"`pecan.conf.app.hooks` or manually in your project's `app.py` ",
"file."]),
DeprecationWarning
)
return app |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'redirect'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'internal'}, {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '15', 'type': 'dictionary', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'add_slash'}; {'id': '18', 'type': 'False', 'children': []}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'block', 'children': ['23', '25', '33', '110', '118', '146', '155']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'''\n Perform a redirect, either internal or external. An internal redirect\n performs the redirect server-side, while the external redirect utilizes\n an HTTP 302 status code.\n :param location: The HTTP location to redirect to.\n :param internal: A boolean indicating whether the redirect should be\n internal.\n :param code: The HTTP status code to use for the redirect. Defaults to 302.\n :param headers: Any HTTP headers to send with the response, as a\n dictionary.\n :param request: The :class:`pecan.Request` instance to use.\n '''"}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '28', 'type': 'boolean_operator', 'children': ['29', '30'], 'value': 'or'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '33', 'type': 'if_statement', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'add_slash'}, {'id': '35', 'type': 'block', 'children': ['36', '86', '101']}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40', '75']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'location'}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41', '55', '69']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'split_url'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'urlparse'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'urlsplit'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'new_proto'}; {'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': 'request'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'environ'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66']}, {'id': '65', 'type': 'string', 'children': [], 'value': "'HTTP_X_FORWARDED_PROTO'"}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'split_url'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '74']}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'split_url'}, {'id': '73', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'new_proto'}, {'id': '75', 'type': 'else_clause', 'children': ['76']}; {'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': 'split_url'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'urlparse'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'urlsplit'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '91']}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'split_url'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '100'], 'value': '+'}; {'id': '92', 'type': 'call', 'children': ['93', '98']}, {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'split_url'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'rstrip'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '100', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'urlparse'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'urlunsplit'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'split_url'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '113']}, {'id': '111', 'type': 'not_operator', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '117', 'type': 'dictionary', 'children': []}; {'id': '118', 'type': 'if_statement', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'internal'}; {'id': '120', 'type': 'block', 'children': ['121', '131', '141']}, {'id': '121', 'type': 'if_statement', 'children': ['122', '125']}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'is'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '124', 'type': 'None', 'children': []}, {'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': 'ValueError'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'string', 'children': [], 'value': "'Cannot specify a code for internal redirects'"}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '138']}, {'id': '133', 'type': 'subscript', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'environ'}, {'id': '137', 'type': 'string', 'children': [], 'value': "'pecan.recursive.context'"}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'context'}, {'id': '141', 'type': 'raise_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'ForwardRequestException'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '150']}, {'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'is'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'code'}, {'id': '149', 'type': 'None', 'children': []}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '302'}, {'id': '155', 'type': 'raise_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '162']}, {'id': '157', 'type': 'subscript', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'status_map'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '166']}, {'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'location'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'location'}; {'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'headers'} | def redirect(location=None, internal=False, code=None, headers={},
add_slash=False, request=None):
'''
Perform a redirect, either internal or external. An internal redirect
performs the redirect server-side, while the external redirect utilizes
an HTTP 302 status code.
:param location: The HTTP location to redirect to.
:param internal: A boolean indicating whether the redirect should be
internal.
:param code: The HTTP status code to use for the redirect. Defaults to 302.
:param headers: Any HTTP headers to send with the response, as a
dictionary.
:param request: The :class:`pecan.Request` instance to use.
'''
request = request or state.request
if add_slash:
if location is None:
split_url = list(urlparse.urlsplit(request.url))
new_proto = request.environ.get(
'HTTP_X_FORWARDED_PROTO', split_url[0]
)
split_url[0] = new_proto
else:
split_url = urlparse.urlsplit(location)
split_url[2] = split_url[2].rstrip('/') + '/'
location = urlparse.urlunsplit(split_url)
if not headers:
headers = {}
if internal:
if code is not None:
raise ValueError('Cannot specify a code for internal redirects')
request.environ['pecan.recursive.context'] = request.context
raise ForwardRequestException(location)
if code is None:
code = 302
raise exc.status_map[code](location=location, headers=headers) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_args'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'all_params'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'argspec'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'im_self'}; {'id': '10', 'type': 'block', 'children': ['11', '13', '17', '21', '27', '36', '53', '61', '71', '83', '103', '144', '171', '209', '247', '276']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'''\n Determines the arguments for a controller based upon parameters\n passed the argument specification for the controller.\n '''"}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '16', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'varargs'}; {'id': '20', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'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': 'valid_args'}; {'id': '30', 'type': 'subscript', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'argspec'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '34', 'type': 'slice', 'children': ['35']}, {'id': '35', 'type': 'colon', 'children': []}; {'id': '36', 'type': 'if_statement', 'children': ['37', '45']}, {'id': '37', 'type': 'boolean_operator', 'children': ['38', '44'], 'value': 'or'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ismethod'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'im_self'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'valid_args'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'pecan_state'}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'pecan'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '64', 'type': 'list_comprehension', 'children': ['65', '66', '69']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '69', 'type': 'if_clause', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '71', 'type': 'if_statement', 'children': ['72', '75']}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'im_self'}; {'id': '74', 'type': 'None', 'children': []}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'im_self'}, {'id': '83', 'type': 'if_statement', 'children': ['84', '87']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': 'in'}, {'id': '85', 'type': 'string', 'children': [], 'value': "'routing_args'"}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'pecan_state'}, {'id': '87', 'type': 'block', 'children': ['88', '99']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '95'], 'value': '+'}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'pecan_state'}; {'id': '94', 'type': 'string', 'children': [], 'value': "'routing_args'"}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '99', 'type': 'delete_statement', 'children': ['100']}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'pecan_state'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'routing_args'"}, {'id': '103', 'type': 'if_statement', 'children': ['104', '107']}; {'id': '104', 'type': 'boolean_operator', 'children': ['105', '106'], 'value': 'and'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'valid_args'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '107', 'type': 'block', 'children': ['108', '122', '133']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '116', 'type': 'slice', 'children': ['117', '118']}, {'id': '117', 'type': 'colon', 'children': []}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'valid_args'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '127', 'type': 'slice', 'children': ['128', '132']}; {'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_args'}; {'id': '132', 'type': 'colon', 'children': []}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'valid_args'}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'valid_args'}; {'id': '138', 'type': 'slice', 'children': ['139', '143']}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '143', 'type': 'colon', 'children': []}; {'id': '144', 'type': 'if_statement', 'children': ['145', '152']}, {'id': '145', 'type': 'list_comprehension', 'children': ['146', '147', '150']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '147', 'type': 'for_in_clause', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '150', 'type': 'if_clause', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '152', 'type': 'block', 'children': ['153', '164']}, {'id': '153', 'type': 'if_statement', 'children': ['154', '158']}; {'id': '154', 'type': 'not_operator', 'children': ['155']}, {'id': '155', 'type': 'subscript', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'argspec'}, {'id': '157', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'abort'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'integer', 'children': [], 'value': '404'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'varargs'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '171', 'type': 'if_statement', 'children': ['172', '175', '201']}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '174', 'type': 'integer', 'children': [], 'value': '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': 'defaults'}, {'id': '179', 'type': 'call', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'izip'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '198']}, {'id': '185', 'type': 'subscript', 'children': ['186', '189']}; {'id': '186', 'type': 'subscript', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '188', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '189', 'type': 'slice', 'children': ['190', '197']}; {'id': '190', 'type': 'unary_operator', 'children': ['191'], 'value': '-'}, {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'subscript', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '197', 'type': 'colon', 'children': []}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '200', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '201', 'type': 'else_clause', 'children': ['202']}; {'id': '202', 'type': 'block', 'children': ['203']}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '206', 'type': 'call', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '208', 'type': 'argument_list', 'children': []}, {'id': '209', 'type': 'for_statement', 'children': ['210', '211', '212']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'valid_args'}; {'id': '212', 'type': 'block', 'children': ['213']}, {'id': '213', 'type': 'if_statement', 'children': ['214', '217', '230', '244']}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'in'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'all_params'}, {'id': '217', 'type': 'block', 'children': ['218']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'call', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'all_params'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '230', 'type': 'elif_clause', 'children': ['231', '234']}, {'id': '231', 'type': 'comparison_operator', 'children': ['232', '233'], 'value': 'in'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '234', 'type': 'block', 'children': ['235']}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'call', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}, {'id': '241', 'type': 'subscript', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'defaults'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '244', 'type': 'else_clause', 'children': ['245']}, {'id': '245', 'type': 'block', 'children': ['246']}; {'id': '246', 'type': 'break_statement', 'children': []}, {'id': '247', 'type': 'if_statement', 'children': ['248', '251']}; {'id': '248', 'type': 'subscript', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '250', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'for_statement', 'children': ['253', '256', '262']}, {'id': '253', 'type': 'pattern_list', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'all_params'}; {'id': '262', 'type': 'block', 'children': ['263']}, {'id': '263', 'type': 'if_statement', 'children': ['264', '269']}; {'id': '264', 'type': 'comparison_operator', 'children': ['265', '266'], 'value': 'not'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '266', 'type': 'subscript', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '268', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '269', 'type': 'block', 'children': ['270']}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'assignment', 'children': ['272', '275']}; {'id': '272', 'type': 'subscript', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '276', 'type': 'return_statement', 'children': ['277']}, {'id': '277', 'type': 'expression_list', 'children': ['278', '279', '280']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'varargs'} | def get_args(self, state, all_params, remainder, argspec, im_self):
'''
Determines the arguments for a controller based upon parameters
passed the argument specification for the controller.
'''
args = []
varargs = []
kwargs = dict()
valid_args = argspec.args[:]
if ismethod(state.controller) or im_self:
valid_args.pop(0)
pecan_state = state.request.pecan
remainder = [x for x in remainder if x]
if im_self is not None:
args.append(im_self)
if 'routing_args' in pecan_state:
remainder = pecan_state['routing_args'] + list(remainder)
del pecan_state['routing_args']
if valid_args and remainder:
args.extend(remainder[:len(valid_args)])
remainder = remainder[len(valid_args):]
valid_args = valid_args[len(args):]
if [i for i in remainder if i]:
if not argspec[1]:
abort(404)
varargs.extend(remainder)
if argspec[3]:
defaults = dict(izip(argspec[0][-len(argspec[3]):], argspec[3]))
else:
defaults = dict()
for name in valid_args:
if name in all_params:
args.append(all_params.pop(name))
elif name in defaults:
args.append(defaults[name])
else:
break
if argspec[2]:
for name, value in six.iteritems(all_params):
if name not in argspec[0]:
kwargs[name] = value
return args, varargs, kwargs |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_route'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '12', '22', '40', '58', '68', '73', '86', '267']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'string', 'children': [], 'value': "'''\n Routes a request to the appropriate controller and returns its result.\n Performs a bit of validation - refuses to route delete and put actions\n via a GET request).\n '''"}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'import_from_statement', 'children': ['18', '20']}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'pecan'}; {'id': '20', 'type': 'dotted_name', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '25', 'type': 'call', 'children': ['26', '39']}; {'id': '26', 'type': 'attribute', 'children': ['27', '38']}, {'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': 'request'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': "'_method'"}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'if_statement', 'children': ['41', '52']}, {'id': '41', 'type': 'boolean_operator', 'children': ['42', '47'], 'value': 'and'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': '=='}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'GET'"}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'in'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '49', 'type': 'tuple', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'delete'"}, {'id': '51', 'type': 'string', 'children': [], 'value': "'put'"}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'abort'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'integer', 'children': [], 'value': '405'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_find_sub_controllers'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'return_statement', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80', '83']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '%'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'_handle_%s'"}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': '_handle_unknown_method'}; {'id': '86', 'type': 'try_statement', 'children': ['87', '161']}, {'id': '87', 'type': 'block', 'children': ['88', '120', '131', '138']}; {'id': '88', 'type': 'if_statement', 'children': ['89', '100', '109']}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '99'], 'value': '=='}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'attribute', 'children': ['94', '98']}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'getargspec'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '3'}; {'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': 'result'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '109', 'type': 'else_clause', 'children': ['110']}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118', '119']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'argspec'}, {'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': '_get_args_for_controller'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'subscript', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'num_args'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'argspec'}; {'id': '138', 'type': 'if_statement', 'children': ['139', '145']}, {'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': '<'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'num_args'}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '145', 'type': 'block', 'children': ['146', '156']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '_lookup_result'}, {'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': '_handle_lookup'}, {'id': '153', 'type': 'argument_list', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '156', 'type': 'if_statement', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': '_lookup_result'}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'return_statement', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': '_lookup_result'}, {'id': '161', 'type': 'except_clause', 'children': ['162', '175']}; {'id': '162', 'type': 'as_pattern', 'children': ['163', '173']}, {'id': '163', 'type': 'tuple', 'children': ['164', '167', '170']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'HTTPClientError'}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'HTTPNotFound'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'HTTPMethodNotAllowed'}, {'id': '173', 'type': 'as_pattern_target', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '175', 'type': 'block', 'children': ['176', '186', '191', '266']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': '_lookup_result'}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': '_handle_lookup'}, {'id': '183', 'type': 'argument_list', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '186', 'type': 'if_statement', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': '_lookup_result'}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'return_statement', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': '_lookup_result'}, {'id': '191', 'type': 'if_statement', 'children': ['192', '199']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'exc'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'HTTPMethodNotAllowed'}, {'id': '199', 'type': 'block', 'children': ['200', '255']}; {'id': '200', 'type': 'function_definition', 'children': ['201', '202', '203']}, {'id': '201', 'type': 'function_name', 'children': [], 'value': 'method_iter'}; {'id': '202', 'type': 'parameters', 'children': []}, {'id': '203', 'type': 'block', 'children': ['204', '226']}; {'id': '204', 'type': 'for_statement', 'children': ['205', '206', '213']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '206', 'type': 'tuple', 'children': ['207', '208', '209', '210', '211', '212']}, {'id': '207', 'type': 'string', 'children': [], 'value': "'get'"}; {'id': '208', 'type': 'string', 'children': [], 'value': "'get_one'"}, {'id': '209', 'type': 'string', 'children': [], 'value': "'get_all'"}; {'id': '210', 'type': 'string', 'children': [], 'value': "'new'"}, {'id': '211', 'type': 'string', 'children': [], 'value': "'edit'"}; {'id': '212', 'type': 'string', 'children': [], 'value': "'get_delete'"}, {'id': '213', 'type': 'block', 'children': ['214']}; {'id': '214', 'type': 'if_statement', 'children': ['215', '221']}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': '_find_controller'}, {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '221', 'type': 'block', 'children': ['222', '225']}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'yield', 'children': ['224']}; {'id': '224', 'type': 'string', 'children': [], 'value': "'GET'"}, {'id': '225', 'type': 'break_statement', 'children': []}; {'id': '226', 'type': 'for_statement', 'children': ['227', '228', '235']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '228', 'type': 'tuple', 'children': ['229', '230', '231', '232', '233', '234']}, {'id': '229', 'type': 'string', 'children': [], 'value': "'HEAD'"}; {'id': '230', 'type': 'string', 'children': [], 'value': "'POST'"}, {'id': '231', 'type': 'string', 'children': [], 'value': "'PUT'"}; {'id': '232', 'type': 'string', 'children': [], 'value': "'DELETE'"}, {'id': '233', 'type': 'string', 'children': [], 'value': "'TRACE'"}; {'id': '234', 'type': 'string', 'children': [], 'value': "'PATCH'"}, {'id': '235', 'type': 'block', 'children': ['236', '244']}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '243', 'type': 'argument_list', 'children': []}; {'id': '244', 'type': 'if_statement', 'children': ['245', '251']}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': '_find_controller'}, {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'yield', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'method'}, {'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': 'e'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'allow'}; {'id': '260', 'type': 'call', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'method_iter'}, {'id': '265', 'type': 'argument_list', 'children': []}; {'id': '266', 'type': 'raise_statement', 'children': []}, {'id': '267', 'type': 'return_statement', 'children': ['268']} | def _route(self, args, request=None):
'''
Routes a request to the appropriate controller and returns its result.
Performs a bit of validation - refuses to route delete and put actions
via a GET request).
'''
if request is None:
from pecan import request
method = request.params.get('_method', request.method).lower()
if request.method == 'GET' and method in ('delete', 'put'):
abort(405)
result = self._find_sub_controllers(args, request)
if result:
return result
handler = getattr(
self,
'_handle_%s' % method,
self._handle_unknown_method
)
try:
if len(getargspec(handler).args) == 3:
result = handler(method, args)
else:
result = handler(method, args, request)
argspec = self._get_args_for_controller(result[0])
num_args = len(argspec)
if num_args < len(args):
_lookup_result = self._handle_lookup(args, request)
if _lookup_result:
return _lookup_result
except (exc.HTTPClientError, exc.HTTPNotFound,
exc.HTTPMethodNotAllowed) as e:
_lookup_result = self._handle_lookup(args, request)
if _lookup_result:
return _lookup_result
if isinstance(e, exc.HTTPMethodNotAllowed):
def method_iter():
for func in ('get', 'get_one', 'get_all', 'new', 'edit',
'get_delete'):
if self._find_controller(func):
yield 'GET'
break
for method in ('HEAD', 'POST', 'PUT', 'DELETE', 'TRACE',
'PATCH'):
func = method.lower()
if self._find_controller(func):
yield method
e.allow = sorted(method_iter())
raise
return result |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_handle_get'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '13', '27', '82', '89', '127', '138', '143', '154', '174', '184', '200']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'''\n Routes ``GET`` actions to the appropriate controller.\n '''"}, {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '16', 'type': 'None', 'children': []}, {'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': '_raise_method_deprecation_warning'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_handle_get'}, {'id': '27', 'type': 'if_statement', 'children': ['28', '35']}; {'id': '28', 'type': 'boolean_operator', 'children': ['29', '31'], 'value': 'or'}, {'id': '29', 'type': 'not_operator', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '=='}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '33', 'type': 'list', 'children': ['34'], 'value': "['']"}; {'id': '34', 'type': 'string', 'children': [], 'value': "''"}, {'id': '35', 'type': 'block', 'children': ['36', '51', '61', '77']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '48']}, {'id': '43', 'type': 'attribute', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'moves'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': '_find_controller'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}, {'id': '59', 'type': 'string', 'children': [], 'value': "'get_all'"}; {'id': '60', 'type': 'string', 'children': [], 'value': "'get'"}, {'id': '61', 'type': 'if_statement', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '63', 'type': 'block', 'children': ['64', '73']}; {'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': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_handle_bad_rest_arguments'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71', '72']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'expression_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '76', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'abort'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'integer', 'children': [], 'value': '405'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'method_name'}, {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '87', 'type': 'unary_operator', 'children': ['88'], 'value': '-'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '89', 'type': 'if_statement', 'children': ['90', '96']}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'in'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'method_name'}; {'id': '92', 'type': 'tuple', 'children': ['93', '94', '95']}, {'id': '93', 'type': 'string', 'children': [], 'value': "'new'"}; {'id': '94', 'type': 'string', 'children': [], 'value': "'edit'"}, {'id': '95', 'type': 'string', 'children': [], 'value': "'delete'"}; {'id': '96', 'type': 'block', 'children': ['97', '106', '115']}, {'id': '97', 'type': 'if_statement', 'children': ['98', '101']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': '=='}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'method_name'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'delete'"}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'method_name'}, {'id': '105', 'type': 'string', 'children': [], 'value': "'get_delete'"}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': '_find_controller'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'method_name'}, {'id': '115', 'type': 'if_statement', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'return_statement', 'children': ['119']}, {'id': '119', 'type': 'expression_list', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '123', 'type': 'slice', 'children': ['124', '125']}; {'id': '124', 'type': 'colon', 'children': []}, {'id': '125', 'type': 'unary_operator', 'children': ['126'], 'value': '-'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': '_handle_custom_action'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '136', '137']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '138', 'type': 'if_statement', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '140', 'type': 'block', 'children': ['141']}, {'id': '141', 'type': 'return_statement', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': '_lookup_child'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '153', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '154', 'type': 'if_statement', 'children': ['155', '162']}, {'id': '155', 'type': 'boolean_operator', 'children': ['156', '157'], 'value': 'and'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '157', 'type': 'not_operator', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'ismethod'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'return_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'lookup_controller'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '168', '173']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '168', 'type': 'subscript', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '170', 'type': 'slice', 'children': ['171', '172']}, {'id': '171', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '172', 'type': 'colon', 'children': []}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': '_find_controller'}, {'id': '181', 'type': 'argument_list', 'children': ['182', '183']}; {'id': '182', 'type': 'string', 'children': [], 'value': "'get_one'"}, {'id': '183', 'type': 'string', 'children': [], 'value': "'get'"}; {'id': '184', 'type': 'if_statement', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '186', 'type': 'block', 'children': ['187', '196']}, {'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': 'self'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': '_handle_bad_rest_arguments'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194', '195']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '196', 'type': 'return_statement', 'children': ['197']}, {'id': '197', 'type': 'expression_list', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'abort'}, {'id': '203', 'type': 'argument_list', 'children': ['204']} | def _handle_get(self, method, remainder, request=None):
'''
Routes ``GET`` actions to the appropriate controller.
'''
if request is None:
self._raise_method_deprecation_warning(self._handle_get)
if not remainder or remainder == ['']:
remainder = list(six.moves.filter(bool, remainder))
controller = self._find_controller('get_all', 'get')
if controller:
self._handle_bad_rest_arguments(controller, remainder, request)
return controller, []
abort(405)
method_name = remainder[-1]
if method_name in ('new', 'edit', 'delete'):
if method_name == 'delete':
method_name = 'get_delete'
controller = self._find_controller(method_name)
if controller:
return controller, remainder[:-1]
match = self._handle_custom_action(method, remainder, request)
if match:
return match
controller = self._lookup_child(remainder[0])
if controller and not ismethod(controller):
return lookup_controller(controller, remainder[1:], request)
controller = self._find_controller('get_one', 'get')
if controller:
self._handle_bad_rest_arguments(controller, remainder, request)
return controller, remainder
abort(405) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_handle_delete'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '13', '27', '77', '87', '94', '137']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': "'''\n Routes ``DELETE`` actions to the appropriate controller.\n '''"}, {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': 'is'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '16', 'type': 'None', 'children': []}, {'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': '_raise_method_deprecation_warning'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_handle_delete'}, {'id': '27', 'type': 'if_statement', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '29', 'type': 'block', 'children': ['30', '41', '46', '57']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'match'}, {'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': '_handle_custom_action'}, {'id': '37', 'type': 'argument_list', 'children': ['38', '39', '40']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'return_statement', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_lookup_child'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '65']}; {'id': '58', 'type': 'boolean_operator', 'children': ['59', '60'], 'value': 'and'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'id': '60', 'type': 'not_operator', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ismethod'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'return_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'lookup_controller'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71', '76']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '73', 'type': 'slice', 'children': ['74', '75']}; {'id': '74', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '75', 'type': 'colon', 'children': []}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'controller'}; {'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': '_find_controller'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86']}, {'id': '85', 'type': 'string', 'children': [], 'value': "'post_delete'"}; {'id': '86', 'type': 'string', 'children': [], 'value': "'delete'"}, {'id': '87', 'type': 'if_statement', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'return_statement', 'children': ['91']}, {'id': '91', 'type': 'expression_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'controller'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '94', 'type': 'if_statement', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '96', 'type': 'block', 'children': ['97', '112', '123']}, {'id': '97', 'type': 'if_statement', 'children': ['98', '106']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': '_find_controller'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '105', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'abort'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'integer', 'children': [], 'value': '405'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'sub_controller'}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_lookup_child'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'subscript', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'remainder'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '123', 'type': 'if_statement', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'sub_controller'}, {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'return_statement', 'children': ['127']}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'lookup_controller'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131', '136']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'sub_controller'}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'remainder'}, {'id': '133', 'type': 'slice', 'children': ['134', '135']}; {'id': '134', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '135', 'type': 'colon', 'children': []}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'abort'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'integer', 'children': [], 'value': '405'} | def _handle_delete(self, method, remainder, request=None):
'''
Routes ``DELETE`` actions to the appropriate controller.
'''
if request is None:
self._raise_method_deprecation_warning(self._handle_delete)
if remainder:
match = self._handle_custom_action(method, remainder, request)
if match:
return match
controller = self._lookup_child(remainder[0])
if controller and not ismethod(controller):
return lookup_controller(controller, remainder[1:], request)
controller = self._find_controller('post_delete', 'delete')
if controller:
return controller, remainder
if remainder:
if self._find_controller(remainder[0]):
abort(405)
sub_controller = self._lookup_child(remainder[0])
if sub_controller:
return lookup_controller(sub_controller, remainder[1:],
request)
abort(405) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'gunicorn_run'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '53', '230']}, {'id': '5', 'type': 'try_statement', 'children': ['6', '14']}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'import_from_statement', 'children': ['8', '12']}; {'id': '8', 'type': 'dotted_name', 'children': ['9', '10', '11']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'gunicorn'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'wsgiapp'}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'WSGIApplication'}; {'id': '14', 'type': 'except_clause', 'children': ['15', '19']}, {'id': '15', 'type': 'as_pattern', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ImportError'}, {'id': '17', 'type': 'as_pattern_target', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '19', 'type': 'block', 'children': ['20', '26', '35', '39', '52']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'arg0'}, {'id': '29', 'type': 'conditional_expression', 'children': ['30', '33', '34'], 'value': 'if'}; {'id': '30', 'type': 'subscript', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '32', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '34', 'type': 'string', 'children': [], 'value': "''"}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'augmented_assignment', 'children': ['37', '38'], 'value': '+='}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'arg0'}; {'id': '38', 'type': 'string', 'children': [], 'value': "' (are you sure `gunicorn` is installed?)'"}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '47'], 'value': '+'}, {'id': '45', 'type': 'tuple', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'arg0'}, {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '49', 'type': 'slice', 'children': ['50', '51']}; {'id': '50', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '51', 'type': 'colon', 'children': []}; {'id': '52', 'type': 'raise_statement', 'children': []}, {'id': '53', 'type': 'class_definition', 'children': ['54', '55', '57']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'PecanApplication'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'WSGIApplication'}, {'id': '57', 'type': 'block', 'children': ['58', '212']}; {'id': '58', 'type': 'function_definition', 'children': ['59', '60', '65']}, {'id': '59', 'type': 'function_name', 'children': [], 'value': 'init'}; {'id': '60', 'type': 'parameters', 'children': ['61', '62', '63', '64']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'parser'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'opts'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '65', 'type': 'block', 'children': ['66', '81', '108', '123', '147', '155', '165', '169', '210']}; {'id': '66', 'type': 'if_statement', 'children': ['67', '73']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '72'], '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': 'identifier', 'children': [], 'value': 'args'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'string', 'children': [], 'value': '"No configuration file was specified."'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'cfgfname'}; {'id': '86', 'type': 'call', 'children': ['87', '92']}, {'id': '87', 'type': 'attribute', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'normpath'}; {'id': '92', 'type': 'argument_list', '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': 'join'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '105']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'getcwd'}; {'id': '104', 'type': 'argument_list', 'children': []}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'cfgfname'}, {'id': '113', 'type': 'call', 'children': ['114', '119']}; {'id': '114', 'type': 'attribute', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'abspath'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'cfgfname'}, {'id': '123', 'type': 'if_statement', 'children': ['124', '135']}; {'id': '124', 'type': 'not_operator', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '131']}; {'id': '126', 'type': 'attribute', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'cfgfname'}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '144'], 'value': '%'}, {'id': '143', 'type': 'string', 'children': [], 'value': '"Config file not found: %s"'}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'cfgfname'}, {'id': '147', 'type': 'import_from_statement', 'children': ['148', '151', '153']}; {'id': '148', 'type': 'dotted_name', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'pecan'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'configuration'}, {'id': '151', 'type': 'dotted_name', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': '_runtime_conf'}, {'id': '153', 'type': 'dotted_name', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'set_config'}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'set_config'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'cfgfname'}; {'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'overwrite'}; {'id': '164', 'type': 'True', 'children': []}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '168', 'type': 'dictionary', 'children': []}, {'id': '169', 'type': 'if_statement', 'children': ['170', '176']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': '_runtime_conf'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'string', 'children': [], 'value': "'server'"}; {'id': '176', 'type': 'block', 'children': ['177', '183']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'server'}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': '_runtime_conf'}; {'id': '182', 'type': 'string', 'children': [], 'value': "'server'"}, {'id': '183', 'type': 'if_statement', 'children': ['184', '195']}; {'id': '184', 'type': 'boolean_operator', 'children': ['185', '190'], 'value': 'and'}, {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '187', 'type': 'argument_list', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'server'}, {'id': '189', 'type': 'string', 'children': [], 'value': "'host'"}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'server'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'port'"}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '201']}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '200', 'type': 'string', 'children': [], 'value': "'bind'"}, {'id': '201', 'type': 'binary_operator', 'children': ['202', '203'], 'value': '%'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'%s:%s'"}, {'id': '203', 'type': 'tuple', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'server'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'server'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'port'}; {'id': '210', 'type': 'return_statement', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '212', 'type': 'function_definition', 'children': ['213', '214', '216']}, {'id': '213', 'type': 'function_name', 'children': [], 'value': 'load'}; {'id': '214', 'type': 'parameters', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '216', 'type': 'block', 'children': ['217', '223']}, {'id': '217', 'type': 'import_from_statement', 'children': ['218', '221']}; {'id': '218', 'type': 'dotted_name', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'pecan'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'deploy'}, {'id': '221', 'type': 'dotted_name', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'deploy'}, {'id': '223', 'type': 'return_statement', 'children': ['224']}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'deploy'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'cfgfname'}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'call', 'children': ['232', '238']}; {'id': '232', 'type': 'attribute', 'children': ['233', '237']}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'PecanApplication'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'string', 'children': [], 'value': '"%(prog)s [OPTIONS] config.py"'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'run'} | def gunicorn_run():
try:
from gunicorn.app.wsgiapp import WSGIApplication
except ImportError as exc:
args = exc.args
arg0 = args[0] if args else ''
arg0 += ' (are you sure `gunicorn` is installed?)'
exc.args = (arg0,) + args[1:]
raise
class PecanApplication(WSGIApplication):
def init(self, parser, opts, args):
if len(args) != 1:
parser.error("No configuration file was specified.")
self.cfgfname = os.path.normpath(
os.path.join(os.getcwd(), args[0])
)
self.cfgfname = os.path.abspath(self.cfgfname)
if not os.path.exists(self.cfgfname):
parser.error("Config file not found: %s" % self.cfgfname)
from pecan.configuration import _runtime_conf, set_config
set_config(self.cfgfname, overwrite=True)
cfg = {}
if _runtime_conf.get('server'):
server = _runtime_conf['server']
if hasattr(server, 'host') and hasattr(server, 'port'):
cfg['bind'] = '%s:%s' % (
server.host, server.port
)
return cfg
def load(self):
from pecan.deploy import deploy
return deploy(self.cfgfname)
PecanApplication("%(prog)s [OPTIONS] config.py").run() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'expose'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'generic'}, {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'route'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'dictionary_splat_pattern', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '15', 'type': 'block', 'children': ['16', '18', '28', '37', '192']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'string', 'children': [], 'value': '\'\'\'\n Decorator used to flag controller methods as being "exposed" for\n access via HTTP, and to configure that access.\n :param template: The path to a template, relative to the base template\n directory. Can also be passed a string representing\n a special or custom renderer, such as ``\'json\'`` for\n :ref:`expose_json`.\n :param content_type: The content-type to use for this template.\n :param generic: A boolean which flags this as a "generic" controller,\n which uses generic functions based upon\n ``functools.singledispatch`` generic functions. Allows you\n to split a single controller into multiple paths based upon\n HTTP method.\n :param route: The name of the path segment to match (excluding\n separator characters, like `/`). Defaults to the name of\n the function itself, but this can be used to resolve paths\n which are not valid Python function names, e.g., if you\n wanted to route a function to `some-special-path\'.\n \'\'\''}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'content_type'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'kw'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'content_type'"}, {'id': '27', 'type': 'string', 'children': [], 'value': "'text/html'"}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': '=='}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'template'}, {'id': '31', 'type': 'string', 'children': [], 'value': "'json'"}; {'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': 'content_type'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'application/json'"}, {'id': '37', 'type': 'function_definition', 'children': ['38', '39', '41']}; {'id': '38', 'type': 'function_name', 'children': [], 'value': 'decorate'}, {'id': '39', 'type': 'parameters', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '41', 'type': 'block', 'children': ['42', '48', '55', '63', '94', '100', '113', '125', '181', '190']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'exposed'}, {'id': '47', 'type': 'True', 'children': []}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': '_cfg'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '60']}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '59', 'type': 'string', 'children': [], 'value': "'explicit_content_type'"}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'in'}, {'id': '61', 'type': 'string', 'children': [], 'value': "'content_type'"}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'kw'}, {'id': '63', 'type': 'if_statement', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'route'}, {'id': '65', 'type': 'block', 'children': ['66', '71', '86']}; {'id': '66', 'type': 'import_from_statement', 'children': ['67', '69']}, {'id': '67', 'type': 'dotted_name', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'pecan'}, {'id': '69', 'type': 'dotted_name', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'routing'}, {'id': '71', 'type': 'if_statement', 'children': ['72', '78']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'string', 'children': [], 'value': "'generic_handler'"}; {'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': 'ValueError'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'concatenated_string', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': "'Path segments cannot be overridden for generic '"}, {'id': '85', 'type': 'string', 'children': [], 'value': "'controllers.'"}; {'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': 'routing'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'route'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'route'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'f'}; {'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': 'cfg'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'content_type'"}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'content_type'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '111']}; {'id': '102', 'type': 'attribute', 'children': ['103', '110']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'setdefault'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'template'"}, {'id': '109', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'template'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '124']}, {'id': '115', 'type': 'subscript', 'children': ['116', '123']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122']}, {'id': '121', 'type': 'string', 'children': [], 'value': "'content_types'"}; {'id': '122', 'type': 'dictionary', 'children': []}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'content_type'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'template'}, {'id': '125', 'type': 'if_statement', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'generic'}, {'id': '127', 'type': 'block', 'children': ['128', '149', '155', '166', '172']}; {'id': '128', 'type': 'if_statement', 'children': ['129', '137']}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': 'in'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '133', 'type': 'tuple', 'children': ['134', '135', '136']}; {'id': '134', 'type': 'string', 'children': [], 'value': "'_default'"}, {'id': '135', 'type': 'string', 'children': [], 'value': "'_lookup'"}; {'id': '136', 'type': 'string', 'children': [], 'value': "'_route'"}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'raise_statement', 'children': ['139']}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '146'], 'value': '%'}, {'id': '143', 'type': 'concatenated_string', 'children': ['144', '145']}; {'id': '144', 'type': 'string', 'children': [], 'value': "'The special method %s cannot be used as a generic '"}, {'id': '145', 'type': 'string', 'children': [], 'value': "'controller'"}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '154']}, {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '153', 'type': 'string', 'children': [], 'value': "'generic'"}; {'id': '154', 'type': 'True', 'children': []}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '160']}, {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '159', 'type': 'string', 'children': [], 'value': "'generic_handlers'"}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '171']}; {'id': '168', 'type': 'subscript', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '170', 'type': 'string', 'children': [], 'value': "'allowed_methods'"}, {'id': '171', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'when'}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'when_for'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '186']}, {'id': '183', 'type': 'subscript', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '185', 'type': 'string', 'children': [], 'value': "'argspec'"}; {'id': '186', 'type': 'call', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'getargspec'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '190', 'type': 'return_statement', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '192', 'type': 'return_statement', 'children': ['193']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'decorate'} | def expose(template=None,
generic=False,
route=None,
**kw):
'''
Decorator used to flag controller methods as being "exposed" for
access via HTTP, and to configure that access.
:param template: The path to a template, relative to the base template
directory. Can also be passed a string representing
a special or custom renderer, such as ``'json'`` for
:ref:`expose_json`.
:param content_type: The content-type to use for this template.
:param generic: A boolean which flags this as a "generic" controller,
which uses generic functions based upon
``functools.singledispatch`` generic functions. Allows you
to split a single controller into multiple paths based upon
HTTP method.
:param route: The name of the path segment to match (excluding
separator characters, like `/`). Defaults to the name of
the function itself, but this can be used to resolve paths
which are not valid Python function names, e.g., if you
wanted to route a function to `some-special-path'.
'''
content_type = kw.get('content_type', 'text/html')
if template == 'json':
content_type = 'application/json'
def decorate(f):
f.exposed = True
cfg = _cfg(f)
cfg['explicit_content_type'] = 'content_type' in kw
if route:
from pecan import routing
if cfg.get('generic_handler'):
raise ValueError(
'Path segments cannot be overridden for generic '
'controllers.'
)
routing.route(route, f)
cfg['content_type'] = content_type
cfg.setdefault('template', []).append(template)
cfg.setdefault('content_types', {})[content_type] = template
if generic:
if f.__name__ in ('_default', '_lookup', '_route'):
raise ValueError(
'The special method %s cannot be used as a generic '
'controller' % f.__name__
)
cfg['generic'] = True
cfg['generic_handlers'] = dict(DEFAULT=f)
cfg['allowed_methods'] = []
f.when = when_for(f)
cfg['argspec'] = getargspec(f)
return f
return decorate |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_operations_bulk'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'payload'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '29', '33', '37', '41', '134', '144']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '13']}, {'id': '9', 'type': 'pattern_list', 'children': ['10', '11', '12']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'valid_indices'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_check_agent_id_bulk'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'valid_payload'}; {'id': '22', 'type': 'list_comprehension', 'children': ['23', '26']}, {'id': '23', 'type': 'subscript', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'payload'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'valid_indices'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'chunked_data'}; {'id': '32', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'current_chunk'}; {'id': '36', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'current_chunk_size'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '41', 'type': 'for_statement', 'children': ['42', '43', '44']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'agent'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'valid_payload'}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'if_statement', 'children': ['46', '58']}; {'id': '46', 'type': 'parenthesized_expression', 'children': ['47'], 'value': '()'}, {'id': '47', 'type': 'boolean_operator', 'children': ['48', '51'], 'value': 'and'}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '50', 'type': 'string', 'children': [], 'value': '"operations"'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '57']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '56', 'type': 'string', 'children': [], 'value': '"operations"'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '58', 'type': 'block', 'children': ['59', '90']}, {'id': '59', 'type': 'if_statement', 'children': ['60', '74']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '69'], 'value': '>'}, {'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '+'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'current_chunk_size'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '68', 'type': 'string', 'children': [], 'value': '"operations"'}, {'id': '69', 'type': 'subscript', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '73', 'type': 'string', 'children': [], 'value': '"operationsChunksSize"'}; {'id': '74', 'type': 'block', 'children': ['75', '82', '86']}, {'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': 'chunked_data'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'current_chunk'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'current_chunk_size'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'current_chunk'}, {'id': '89', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '103', '116']}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '98'], 'value': '>'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'agent'}, {'id': '97', 'type': 'string', 'children': [], 'value': '"operations"'}; {'id': '98', 'type': 'subscript', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '102', 'type': 'string', 'children': [], 'value': '"operationsChunksSize"'}, {'id': '103', 'type': 'block', 'children': ['104', '112']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'chunked_data'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'list', 'children': ['111'], 'value': '[agent]'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'current_chunk_size'}, {'id': '115', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '116', 'type': 'else_clause', 'children': ['117']}, {'id': '117', 'type': 'block', 'children': ['118', '127']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'augmented_assignment', 'children': ['120', '121'], 'value': '+='}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'current_chunk_size'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '126', 'type': 'string', 'children': [], 'value': '"operations"'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'current_chunk'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '134', 'type': 'if_statement', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'current_chunk'}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'chunked_data'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'current_chunk'}; {'id': '144', 'type': 'return_statement', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '_add_operations_bulk'}, {'id': '149', 'type': 'argument_list', 'children': ['150']} | def add_operations_bulk(self, payload):
valid_indices, _, _ = self._check_agent_id_bulk(payload)
valid_payload = [payload[i] for i in valid_indices]
chunked_data = []
current_chunk = []
current_chunk_size = 0
for agent in valid_payload:
if (agent["operations"] and isinstance(agent["operations"], list)):
if current_chunk_size + len(agent["operations"]) > self.config["operationsChunksSize"]:
chunked_data.append(current_chunk)
current_chunk_size = 0
current_chunk = []
if len(agent["operations"]) > self.config["operationsChunksSize"]:
chunked_data.append([agent])
current_chunk_size = 0
else:
current_chunk_size += len(agent["operations"])
current_chunk.append(agent)
if current_chunk:
chunked_data.append(current_chunk)
return self._add_operations_bulk(chunked_data) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '8', 'type': 'attribute', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'pydle'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_ENCODING'}, {'id': '13', 'type': 'block', 'children': ['14', '18', '45', '59', '107', '124', '165', '212', '227', '333', '353']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'valid'}, {'id': '17', 'type': 'True', 'children': []}; {'id': '18', 'type': 'try_statement', 'children': ['19', '29']}, {'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': 'message'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'encoding'}, {'id': '29', 'type': 'except_clause', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'pydle'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'FALLBACK_ENCODING'}, {'id': '45', 'type': 'if_statement', 'children': ['46', '54']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '51'], 'value': '>'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'MESSAGE_LENGTH_LIMIT'}; {'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': 'valid'}; {'id': '58', 'type': 'False', 'children': []}, {'id': '59', 'type': 'if_statement', 'children': ['60', '68', '83']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'LINE_SEPARATOR'}; {'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': 'message'}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '74', 'type': 'slice', 'children': ['75', '76']}, {'id': '75', 'type': 'colon', 'children': []}; {'id': '76', 'type': 'unary_operator', 'children': ['77'], 'value': '-'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'LINE_SEPARATOR'}, {'id': '83', 'type': 'elif_clause', 'children': ['84', '92']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'MINIMAL_LINE_SEPARATOR'}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '98', 'type': 'slice', 'children': ['99', '100']}, {'id': '99', 'type': 'colon', 'children': []}; {'id': '100', 'type': 'unary_operator', 'children': ['101'], 'value': '-'}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'MINIMAL_LINE_SEPARATOR'}, {'id': '107', 'type': 'if_statement', 'children': ['108', '119']}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '110', 'type': 'generator_expression', 'children': ['111', '114']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'in'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'ch'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '114', 'type': 'for_in_clause', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'ch'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'FORBIDDEN_CHARACTERS'}, {'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': 'valid'}, {'id': '123', 'type': 'False', 'children': []}; {'id': '124', 'type': 'if_statement', 'children': ['125', '131', '148']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'string', 'children': [], 'value': "':'"}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '135', 'type': 'call', 'children': ['136', '141']}; {'id': '136', 'type': 'attribute', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'ARGUMENT_SEPARATOR'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '141', 'type': 'argument_list', 'children': ['142', '147']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '144', 'type': 'slice', 'children': ['145', '146']}, {'id': '145', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '146', 'type': 'colon', 'children': []}, {'id': '147', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '148', 'type': 'else_clause', 'children': ['149']}, {'id': '149', 'type': 'block', 'children': ['150']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '153', 'type': 'binary_operator', 'children': ['154', '156'], 'value': '+'}; {'id': '154', 'type': 'list', 'children': ['155'], 'value': '[ None ]'}, {'id': '155', 'type': 'None', 'children': []}; {'id': '156', 'type': 'call', 'children': ['157', '162']}, {'id': '157', 'type': 'attribute', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'ARGUMENT_SEPARATOR'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '165', 'type': 'if_statement', 'children': ['166', '172', '180', '198']}; {'id': '166', 'type': 'comparison_operator', 'children': ['167', '171'], 'value': '=='}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '171', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '172', 'type': 'block', 'children': ['173']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '179']}, {'id': '175', 'type': 'pattern_list', 'children': ['176', '177', '178']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'raw_params'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '180', 'type': 'elif_clause', 'children': ['181', '187']}, {'id': '181', 'type': 'comparison_operator', 'children': ['182', '186'], 'value': '=='}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '187', 'type': 'block', 'children': ['188', '194']}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '193']}; {'id': '190', 'type': 'pattern_list', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'raw_params'}, {'id': '197', 'type': 'string', 'children': [], 'value': "''"}; {'id': '198', 'type': 'else_clause', 'children': ['199']}, {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'raise_statement', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '207']}; {'id': '202', 'type': 'attribute', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'pydle'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'ProtocolViolation'}, {'id': '207', 'type': 'argument_list', 'children': ['208', '209']}; {'id': '208', 'type': 'string', 'children': [], 'value': "'Improper IRC message format: not enough elements.'"}, {'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '212', 'type': 'if_statement', 'children': ['213', '222']}, {'id': '213', 'type': 'not_operator', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '220']}, {'id': '215', 'type': 'attribute', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'COMMAND_PATTERN'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '222', 'type': 'block', 'children': ['223']}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '226', 'type': 'False', 'children': []}, {'id': '227', 'type': 'if_statement', 'children': ['228', '236', '251', '313', '327']}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'raw_params'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'TRAILING_PREFIX'}; {'id': '236', 'type': 'block', 'children': ['237']}, {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '240', 'type': 'list', 'children': ['241'], 'value': '[ raw_params[len(protocol.TRAILING_PREFIX):] ]'}, {'id': '241', 'type': 'subscript', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'raw_params'}, {'id': '243', 'type': 'slice', 'children': ['244', '250']}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'TRAILING_PREFIX'}; {'id': '250', 'type': 'colon', 'children': []}, {'id': '251', 'type': 'elif_clause', 'children': ['252', '259']}; {'id': '252', 'type': 'comparison_operator', 'children': ['253', '258'], 'value': 'in'}, {'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '+'}; {'id': '254', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'TRAILING_PREFIX'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'raw_params'}, {'id': '259', 'type': 'block', 'children': ['260', '273', '293']}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '263', 'type': 'call', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'raw_params'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'binary_operator', 'children': ['269', '270'], 'value': '+'}, {'id': '269', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'TRAILING_PREFIX'}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '276', 'type': 'call', 'children': ['277', '282']}, {'id': '277', 'type': 'attribute', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'ARGUMENT_SEPARATOR'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'call', 'children': ['284', '291']}; {'id': '284', 'type': 'attribute', 'children': ['285', '290']}, {'id': '285', 'type': 'subscript', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'raw_params'}, {'id': '287', 'type': 'slice', 'children': ['288', '289']}; {'id': '288', 'type': 'colon', 'children': []}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'rstrip'}, {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'call', 'children': ['295', '298']}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '298', 'type': 'argument_list', 'children': ['299']}, {'id': '299', 'type': 'subscript', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'raw_params'}, {'id': '301', 'type': 'slice', 'children': ['302', '312']}; {'id': '302', 'type': 'binary_operator', 'children': ['303', '311'], 'value': '+'}, {'id': '303', 'type': 'binary_operator', 'children': ['304', '305'], 'value': '+'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '305', 'type': 'call', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '307', 'type': 'argument_list', 'children': ['308']}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'TRAILING_PREFIX'}, {'id': '311', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '312', 'type': 'colon', 'children': []}, {'id': '313', 'type': 'elif_clause', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'raw_params'}, {'id': '315', 'type': 'block', 'children': ['316']}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'assignment', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '319', 'type': 'call', 'children': ['320', '325']}; {'id': '320', 'type': 'attribute', 'children': ['321', '324']}, {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'ARGUMENT_SEPARATOR'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '325', 'type': 'argument_list', 'children': ['326']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'raw_params'}, {'id': '327', 'type': 'else_clause', 'children': ['328']}; {'id': '328', 'type': 'block', 'children': ['329']}, {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'assignment', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '332', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '333', 'type': 'try_statement', 'children': ['334', '342']}; {'id': '334', 'type': 'block', 'children': ['335']}, {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'assignment', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '338', 'type': 'call', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '340', 'type': 'argument_list', 'children': ['341']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '342', 'type': 'except_clause', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '344', 'type': 'block', 'children': ['345']}, {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'assignment', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '348', 'type': 'call', 'children': ['349', '352']}, {'id': '349', 'type': 'attribute', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '352', 'type': 'argument_list', 'children': []}, {'id': '353', 'type': 'return_statement', 'children': ['354']}; {'id': '354', 'type': 'call', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'RFC1459Message'}; {'id': '356', 'type': 'argument_list', 'children': ['357', '358', '359', '362', '365']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '359', 'type': 'keyword_argument', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '362', 'type': 'keyword_argument', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': '_valid'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'valid'}, {'id': '365', 'type': 'keyword_argument', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': '_raw'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'message'} | def parse(cls, line, encoding=pydle.protocol.DEFAULT_ENCODING):
valid = True
try:
message = line.decode(encoding)
except UnicodeDecodeError:
message = line.decode(pydle.protocol.FALLBACK_ENCODING)
if len(message) > protocol.MESSAGE_LENGTH_LIMIT:
valid = False
if message.endswith(protocol.LINE_SEPARATOR):
message = message[:-len(protocol.LINE_SEPARATOR)]
elif message.endswith(protocol.MINIMAL_LINE_SEPARATOR):
message = message[:-len(protocol.MINIMAL_LINE_SEPARATOR)]
if any(ch in message for ch in protocol.FORBIDDEN_CHARACTERS):
valid = False
if message.startswith(':'):
parts = protocol.ARGUMENT_SEPARATOR.split(message[1:], 2)
else:
parts = [ None ] + protocol.ARGUMENT_SEPARATOR.split(message, 1)
if len(parts) == 3:
source, command, raw_params = parts
elif len(parts) == 2:
source, command = parts
raw_params = ''
else:
raise pydle.protocol.ProtocolViolation('Improper IRC message format: not enough elements.', message=message)
if not protocol.COMMAND_PATTERN.match(command):
valid = False
if raw_params.startswith(protocol.TRAILING_PREFIX):
params = [ raw_params[len(protocol.TRAILING_PREFIX):] ]
elif ' ' + protocol.TRAILING_PREFIX in raw_params:
index = raw_params.find(' ' + protocol.TRAILING_PREFIX)
params = protocol.ARGUMENT_SEPARATOR.split(raw_params[:index].rstrip(' '))
params.append(raw_params[index + len(protocol.TRAILING_PREFIX) + 1:])
elif raw_params:
params = protocol.ARGUMENT_SEPARATOR.split(raw_params)
else:
params = []
try:
command = int(command)
except ValueError:
command = command.upper()
return RFC1459Message(command, params, source=source, _valid=valid, _raw=message) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'construct'}, {'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': 'force'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '18', '55', '63', '73', '143', '160', '202', '208', '248']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '31']}, {'id': '19', 'type': 'boolean_operator', 'children': ['20', '29'], 'value': 'and'}; {'id': '20', 'type': 'not_operator', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'COMMAND_PATTERN'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '29', 'type': 'not_operator', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'force'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'raise_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '39']}; {'id': '34', 'type': 'attribute', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'pydle'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ProtocolViolation'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '52']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'The constructed command does not follow the command pattern ({pat})'"}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'pat'}, {'id': '47', 'type': 'attribute', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'COMMAND_PATTERN'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '52', 'type': 'keyword_argument', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'if_statement', 'children': ['64', '68']}; {'id': '64', 'type': 'not_operator', 'children': ['65']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'augmented_assignment', 'children': ['71', '72'], 'value': '+='}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '72', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '73', 'type': 'for_statement', 'children': ['74', '77', '83']}; {'id': '74', 'type': 'pattern_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'if_statement', 'children': ['85', '97', '135']}, {'id': '85', 'type': 'boolean_operator', 'children': ['86', '92'], 'value': 'or'}; {'id': '86', 'type': 'boolean_operator', 'children': ['87', '89'], 'value': 'or'}, {'id': '87', 'type': 'not_operator', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'in'}; {'id': '90', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '96'], 'value': '=='}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'string', 'children': [], 'value': "':'"}, {'id': '97', 'type': 'block', 'children': ['98', '125']}; {'id': '98', 'type': 'if_statement', 'children': ['99', '112']}, {'id': '99', 'type': 'boolean_operator', 'children': ['100', '110'], 'value': 'and'}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '104'], 'value': '<'}, {'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '+'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '103', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '110', 'type': 'not_operator', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'raise_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '120']}, {'id': '115', 'type': 'attribute', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'pydle'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'ProtocolViolation'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122']}, {'id': '121', 'type': 'string', 'children': [], 'value': "'Only the final parameter of an IRC message can be trailing and thus contain spaces, or start with a colon.'"}; {'id': '122', 'type': 'keyword_argument', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'augmented_assignment', 'children': ['127', '128'], 'value': '+='}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '128', 'type': 'binary_operator', 'children': ['129', '134'], 'value': '+'}, {'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '+'}; {'id': '130', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'TRAILING_PREFIX'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '135', 'type': 'else_clause', 'children': ['136']}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'augmented_assignment', 'children': ['139', '140'], 'value': '+='}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '140', 'type': 'binary_operator', 'children': ['141', '142'], 'value': '+'}, {'id': '141', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '143', 'type': 'if_statement', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '151', 'type': 'binary_operator', 'children': ['152', '159'], 'value': '+'}; {'id': '152', 'type': 'binary_operator', 'children': ['153', '158'], 'value': '+'}, {'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '+'}; {'id': '154', 'type': 'string', 'children': [], 'value': "':'"}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '158', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '160', 'type': 'if_statement', 'children': ['161', '175']}, {'id': '161', 'type': 'boolean_operator', 'children': ['162', '173'], 'value': 'and'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '164', 'type': 'generator_expression', 'children': ['165', '168']}, {'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': 'in'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'ch'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '168', 'type': 'for_in_clause', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ch'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'FORBIDDEN_CHARACTERS'}, {'id': '173', 'type': 'not_operator', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'force'}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'raise_statement', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '183']}; {'id': '178', 'type': 'attribute', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'pydle'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'ProtocolViolation'}, {'id': '183', 'type': 'argument_list', 'children': ['184', '199']}; {'id': '184', 'type': 'call', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'string', 'children': [], 'value': "'The constructed message contains forbidden characters ({chs}).'"}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}, {'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'chs'}, {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'FORBIDDEN_CHARACTERS'}, {'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'augmented_assignment', 'children': ['204', '205'], 'value': '+='}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'LINE_SEPARATOR'}; {'id': '208', 'type': 'if_statement', 'children': ['209', '220']}, {'id': '209', 'type': 'boolean_operator', 'children': ['210', '218'], 'value': 'and'}; {'id': '210', 'type': 'comparison_operator', 'children': ['211', '215'], 'value': '>'}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'MESSAGE_LENGTH_LIMIT'}; {'id': '218', 'type': 'not_operator', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'force'}; {'id': '220', 'type': 'block', 'children': ['221']}, {'id': '221', 'type': 'raise_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': 'pydle'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'protocol'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'ProtocolViolation'}; {'id': '228', 'type': 'argument_list', 'children': ['229', '245']}, {'id': '229', 'type': 'call', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'string', 'children': [], 'value': "'The constructed message is too long. ({len} > {maxlen})'"}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '233', 'type': 'argument_list', 'children': ['234', '240']}; {'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '236', 'type': 'call', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '240', 'type': 'keyword_argument', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'maxlen'}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'protocol'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'MESSAGE_LENGTH_LIMIT'}, {'id': '245', 'type': 'keyword_argument', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'message'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '248', 'type': 'return_statement', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'message'} | def construct(self, force=False):
command = str(self.command)
if not protocol.COMMAND_PATTERN.match(command) and not force:
raise pydle.protocol.ProtocolViolation('The constructed command does not follow the command pattern ({pat})'.format(pat=protocol.COMMAND_PATTERN.pattern), message=command)
message = command.upper()
if not self.params:
message += ' '
for idx, param in enumerate(self.params):
if not param or ' ' in param or param[0] == ':':
if idx + 1 < len(self.params) and not force:
raise pydle.protocol.ProtocolViolation('Only the final parameter of an IRC message can be trailing and thus contain spaces, or start with a colon.', message=param)
message += ' ' + protocol.TRAILING_PREFIX + param
else:
message += ' ' + param
if self.source:
message = ':' + self.source + ' ' + message
if any(ch in message for ch in protocol.FORBIDDEN_CHARACTERS) and not force:
raise pydle.protocol.ProtocolViolation('The constructed message contains forbidden characters ({chs}).'.format(chs=', '.join(protocol.FORBIDDEN_CHARACTERS)), message=message)
message += protocol.LINE_SEPARATOR
if len(message) > protocol.MESSAGE_LENGTH_LIMIT and not force:
raise pydle.protocol.ProtocolViolation('The constructed message is too long. ({len} > {maxlen})'.format(len=len(message), maxlen=protocol.MESSAGE_LENGTH_LIMIT), message=message)
return message |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'ERROR', 'children': ['2', '244', '262', '267', '275', '276', '280', '281', '285', '286', '314', '318', '328', '331', '337', '341', '342']}; {'id': '2', 'type': 'function_definition', 'children': ['3', '4', '6', '132']}, {'id': '3', 'type': 'function_name', 'children': [], 'value': 'split'}; {'id': '4', 'type': 'parameters', 'children': ['5']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '6', 'type': 'ERROR', 'children': ['7', '19', '28', '37', '51', '97', '105', '114', '123', '124', '127', '129']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'scheme'}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'netloc'}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'fragment'}; {'id': '18', 'type': 'string', 'children': [], 'value': "''"}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ip6_start'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'string', 'children': [], 'value': "'['"}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'scheme_end'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': "':'"}, {'id': '37', 'type': 'if_statement', 'children': ['38', '45']}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '42'], 'value': 'and'}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '>'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ip6_start'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': '<'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ip6_start'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'scheme_end'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'scheme_end'}, {'id': '49', 'type': 'unary_operator', 'children': ['50'], 'value': '-'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '51', 'type': 'if_statement', 'children': ['52', '55']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': '>'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'scheme_end'}; {'id': '54', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'for_statement', 'children': ['57', '58', '63', '70']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '60', 'type': 'slice', 'children': ['61', '62']}, {'id': '61', 'type': 'colon', 'children': []}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'scheme_end'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'if_statement', 'children': ['65', '68']}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'not'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'SCHEME_CHARS'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'break_statement', 'children': []}; {'id': '70', 'type': 'else_clause', 'children': ['71']}, {'id': '71', 'type': 'block', 'children': ['72', '84']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'scheme'}, {'id': '75', 'type': 'call', 'children': ['76', '83']}; {'id': '76', 'type': 'attribute', 'children': ['77', '82']}, {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '79', 'type': 'slice', 'children': ['80', '81']}; {'id': '80', 'type': 'colon', 'children': []}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'scheme_end'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'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': 'rest'}, {'id': '87', 'type': 'call', 'children': ['88', '95']}; {'id': '88', 'type': 'attribute', 'children': ['89', '94']}, {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '91', 'type': 'slice', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'scheme_end'}, {'id': '93', 'type': 'colon', 'children': []}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'lstrip'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'string', 'children': [], 'value': "':/'"}, {'id': '97', 'type': 'if_statement', 'children': ['98', '100']}; {'id': '98', 'type': 'not_operator', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'scheme'}; {'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': 'rest'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'l_path'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'rest'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'l_query'}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'string', 'children': [], 'value': "'?'"}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'l_frag'}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '127', 'type': 'ERROR', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'if'}, {'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': '>'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'l_path'}, {'id': '131', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'if_statement', 'children': ['134', '141', '163', '204', '226']}; {'id': '134', 'type': 'boolean_operator', 'children': ['135', '138'], 'value': 'and'}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': '>'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'l_query'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': '>'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'l_frag'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '141', 'type': 'block', 'children': ['142', '150']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'netloc'}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'rest'}, {'id': '147', 'type': 'slice', 'children': ['148', '149']}; {'id': '148', 'type': 'colon', 'children': []}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'l_path'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'rest'}, {'id': '155', 'type': 'slice', 'children': ['156', '157', '158']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'l_path'}, {'id': '157', 'type': 'colon', 'children': []}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'l_query'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'l_frag'}, {'id': '163', 'type': 'elif_clause', 'children': ['164', '167']}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': '>'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'l_query'}; {'id': '166', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'if_statement', 'children': ['169', '172', '190']}, {'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': '>'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'l_query'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'l_path'}; {'id': '172', 'type': 'block', 'children': ['173', '181']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'netloc'}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '178', 'type': 'slice', 'children': ['179', '180']}, {'id': '179', 'type': 'colon', 'children': []}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'l_path'}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '186', 'type': 'slice', 'children': ['187', '188', '189']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'l_path'}; {'id': '188', 'type': 'colon', 'children': []}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'l_query'}; {'id': '190', 'type': 'else_clause', 'children': ['191']}, {'id': '191', 'type': 'block', 'children': ['192', '200']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'netloc'}, {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'rest'}, {'id': '197', 'type': 'slice', 'children': ['198', '199']}; {'id': '198', 'type': 'colon', 'children': []}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'l_query'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'assignment', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '203', 'type': 'string', 'children': [], 'value': "''"}; {'id': '204', 'type': 'elif_clause', 'children': ['205', '208']}, {'id': '205', 'type': 'comparison_operator', 'children': ['206', '207'], 'value': '>'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'l_frag'}, {'id': '207', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '208', 'type': 'block', 'children': ['209', '217']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'netloc'}; {'id': '212', 'type': 'subscript', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '214', 'type': 'slice', 'children': ['215', '216']}, {'id': '215', 'type': 'colon', 'children': []}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'l_path'}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '222', 'type': 'slice', 'children': ['223', '224', '225']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'l_path'}; {'id': '224', 'type': 'colon', 'children': []}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'l_frag'}; {'id': '226', 'type': 'else_clause', 'children': ['227']}, {'id': '227', 'type': 'block', 'children': ['228', '236']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'netloc'}, {'id': '231', 'type': 'subscript', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'rest'}, {'id': '233', 'type': 'slice', 'children': ['234', '235']}; {'id': '234', 'type': 'colon', 'children': []}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'l_path'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'assignment', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '239', 'type': 'subscript', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'rest'}, {'id': '241', 'type': 'slice', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'l_path'}, {'id': '243', 'type': 'colon', 'children': []}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'assignment', 'children': ['246', '247', '249', '257']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'else'}, {'id': '247', 'type': 'ERROR', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'if'}, {'id': '249', 'type': 'type', 'children': ['250']}; {'id': '250', 'type': 'constrained_type', 'children': ['251', '255']}, {'id': '251', 'type': 'type', 'children': ['252']}; {'id': '252', 'type': 'comparison_operator', 'children': ['253', '254'], 'value': '>'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'l_query'}; {'id': '254', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '255', 'type': 'type', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'netloc'}, {'id': '257', 'type': 'subscript', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'rest'}, {'id': '259', 'type': 'slice', 'children': ['260', '261']}; {'id': '260', 'type': 'colon', 'children': []}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'l_query'}; {'id': '262', 'type': 'ERROR', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'elif'}; {'id': '264', 'type': 'comparison_operator', 'children': ['265', '266'], 'value': '>'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'l_frag'}; {'id': '266', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'assignment', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'netloc'}; {'id': '270', 'type': 'subscript', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '272', 'type': 'slice', 'children': ['273', '274']}, {'id': '273', 'type': 'colon', 'children': []}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'l_frag'}, {'id': '275', 'type': 'ERROR', 'children': []}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'netloc'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '280', 'type': 'ERROR', 'children': []}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'comparison_operator', 'children': ['283', '284'], 'value': '>'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'l_query'}; {'id': '284', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '285', 'type': 'ERROR', 'children': []}; {'id': '286', 'type': 'if_statement', 'children': ['287', '290', '302']}, {'id': '287', 'type': 'comparison_operator', 'children': ['288', '289'], 'value': '>'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'l_frag'}, {'id': '289', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '290', 'type': 'block', 'children': ['291']}, {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'assignment', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '294', 'type': 'subscript', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'id': '296', 'type': 'slice', 'children': ['297', '300', '301']}, {'id': '297', 'type': 'binary_operator', 'children': ['298', '299'], 'value': '+'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'l_query'}, {'id': '299', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '300', 'type': 'colon', 'children': []}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'l_frag'}; {'id': '302', 'type': 'else_clause', 'children': ['303']}, {'id': '303', 'type': 'block', 'children': ['304']}; {'id': '304', 'type': 'expression_statement', 'children': ['305']}, {'id': '305', 'type': 'assignment', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'query'}, {'id': '307', 'type': 'subscript', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'rest'}, {'id': '309', 'type': 'slice', 'children': ['310', '313']}; {'id': '310', 'type': 'binary_operator', 'children': ['311', '312'], 'value': '+'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'l_query'}; {'id': '312', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '313', 'type': 'colon', 'children': []}; {'id': '314', 'type': 'ERROR', 'children': ['315']}, {'id': '315', 'type': 'comparison_operator', 'children': ['316', '317'], 'value': '>'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'l_frag'}, {'id': '317', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}, {'id': '319', 'type': 'assignment', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'fragment'}, {'id': '321', 'type': 'subscript', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'rest'}, {'id': '323', 'type': 'slice', 'children': ['324', '327']}; {'id': '324', 'type': 'binary_operator', 'children': ['325', '326'], 'value': '+'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'l_frag'}; {'id': '326', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '327', 'type': 'colon', 'children': []}; {'id': '328', 'type': 'ERROR', 'children': ['329']}, {'id': '329', 'type': 'not_operator', 'children': ['330']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'scheme'}, {'id': '331', 'type': 'expression_statement', 'children': ['332']}; {'id': '332', 'type': 'assignment', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '334', 'type': 'binary_operator', 'children': ['335', '336'], 'value': '+'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'netloc'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '337', 'type': 'expression_statement', 'children': ['338']}; {'id': '338', 'type': 'assignment', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'netloc'}; {'id': '340', 'type': 'string', 'children': [], 'value': "''"}, {'id': '341', 'type': 'ERROR', 'children': []}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}, {'id': '343', 'type': 'call', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'SplitResult'}, {'id': '345', 'type': 'argument_list', 'children': ['346', '347', '348', '349', '350']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'scheme'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'netloc'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'query'} | def split(url):
scheme = netloc = path = query = fragment = ''
ip6_start = url.find('[')
scheme_end = url.find(':')
if ip6_start > 0 and ip6_start < scheme_end:
scheme_end = -1
if scheme_end > 0:
for c in url[:scheme_end]:
if c not in SCHEME_CHARS:
break
else:
scheme = url[:scheme_end].lower()
rest = url[scheme_end:].lstrip(':/')
if not scheme:
rest = url
l_path = rest.find('/')
l_query = rest.find('?')
l_frag = rest.find('
if l_path > 0:
if l_query > 0 and l_frag > 0:
netloc = rest[:l_path]
path = rest[l_path:min(l_query, l_frag)]
elif l_query > 0:
if l_query > l_path:
netloc = rest[:l_path]
path = rest[l_path:l_query]
else:
netloc = rest[:l_query]
path = ''
elif l_frag > 0:
netloc = rest[:l_path]
path = rest[l_path:l_frag]
else:
netloc = rest[:l_path]
path = rest[l_path:]
else:
if l_query > 0:
netloc = rest[:l_query]
elif l_frag > 0:
netloc = rest[:l_frag]
else:
netloc = rest
if l_query > 0:
if l_frag > 0:
query = rest[l_query+1:l_frag]
else:
query = rest[l_query+1:]
if l_frag > 0:
fragment = rest[l_frag+1:]
if not scheme:
path = netloc + path
netloc = ''
return SplitResult(scheme, netloc, path, query, fragment) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'issue_cmd'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'retry'}, {'id': '9', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'with_statement', 'children': ['12', '17']}; {'id': '12', 'type': 'with_clause', 'children': ['13']}, {'id': '13', 'type': 'with_item', 'children': ['14']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_cmd_lock'}, {'id': '17', 'type': 'block', 'children': ['18', '33', '60', '69', '89', '115', '155', '338']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '23']}, {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'connected'}, {'id': '23', 'type': 'block', 'children': ['24', '32']}; {'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': '_LOGGER'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': '"Serial transport closed, not sending command %s"'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '32', 'type': 'return_statement', 'children': []}, {'id': '33', 'type': 'while_statement', 'children': ['34', '42']}; {'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': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': '_cmdq'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '41', 'type': 'argument_list', 'children': []}; {'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': '_LOGGER'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '52']}, {'id': '49', 'type': 'concatenated_string', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': '"Clearing leftover message from command queue:"'}, {'id': '51', 'type': 'string', 'children': [], 'value': '" %s"'}; {'id': '52', 'type': 'await', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '59']}; {'id': '54', 'type': 'attribute', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': '_cmdq'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '59', 'type': 'argument_list', 'children': []}; {'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': '_LOGGER'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67', '68']}; {'id': '66', 'type': 'string', 'children': [], 'value': '"Sending command: %s with value %s"'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '76']}, {'id': '71', 'type': 'attribute', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'transport'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '87']}; {'id': '78', 'type': 'attribute', 'children': ['79', '86']}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'string', 'children': [], 'value': "'{}={}\\r\\n'"}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'string', 'children': [], 'value': "'ascii'"}, {'id': '89', 'type': 'if_statement', 'children': ['90', '93', '104']}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '=='}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'OTGW_CMD_REPORT'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'expect'}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'string', 'children': [], 'value': "r'^{}:\\s*([A-Z]{{2}}|{}=[^$]+)$'"}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '104', 'type': 'else_clause', 'children': ['105']}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'expect'}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'string', 'children': [], 'value': "r'^{}:\\s*([^$]+)$'"}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '115', 'type': 'function_definition', 'children': ['116', '117', '119']}; {'id': '116', 'type': 'function_name', 'children': [], 'value': 'send_again'}, {'id': '117', 'type': 'parameters', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '119', 'type': 'block', 'children': ['120', '122', '131', '135']}; {'id': '120', 'type': 'nonlocal_statement', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'retry'}; {'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', '129', '130']}; {'id': '128', 'type': 'string', 'children': [], 'value': '"Command %s failed with %s, retrying..."'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'augmented_assignment', 'children': ['133', '134'], 'value': '-='}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'retry'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'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': 'self'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'transport'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '153']}; {'id': '144', 'type': 'attribute', 'children': ['145', '152']}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'string', 'children': [], 'value': "'{}={}\\r\\n'"}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '149', 'type': 'argument_list', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'string', 'children': [], 'value': "'ascii'"}, {'id': '155', 'type': 'function_definition', 'children': ['156', '157', '159']}; {'id': '156', 'type': 'function_name', 'children': [], 'value': 'process'}, {'id': '157', 'type': 'parameters', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '159', 'type': 'block', 'children': ['160', '169', '190', '222', '232', '303', '324', '332']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': '_LOGGER'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '165', 'type': 'argument_list', 'children': ['166', '167', '168']}; {'id': '166', 'type': 'string', 'children': [], 'value': '"Got possible response for command %s: %s"'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '169', 'type': 'if_statement', 'children': ['170', '173']}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': 'in'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'OTGW_ERRS'}, {'id': '173', 'type': 'block', 'children': ['174', '183', '189']}; {'id': '174', 'type': 'if_statement', 'children': ['175', '178']}, {'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': '=='}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'retry'}, {'id': '177', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'raise_statement', 'children': ['180']}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'OTGW_ERRS'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'await', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'send_again'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '189', 'type': 'return_statement', 'children': []}; {'id': '190', 'type': 'if_statement', 'children': ['191', '198']}, {'id': '191', 'type': 'boolean_operator', 'children': ['192', '195'], 'value': 'and'}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': '=='}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'OTGW_CMD_MODE'}, {'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': '=='}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '197', 'type': 'string', 'children': [], 'value': "'R'"}; {'id': '198', 'type': 'block', 'children': ['199', '220']}, {'id': '199', 'type': 'while_statement', 'children': ['200', '208']}; {'id': '200', 'type': 'not_operator', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '205', 'type': 'argument_list', 'children': ['206', '207']}; {'id': '206', 'type': 'string', 'children': [], 'value': "r'OpenTherm Gateway \\d+\\.\\d+\\.\\d+'"}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '212', 'type': 'await', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '219']}; {'id': '214', 'type': 'attribute', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': '_cmdq'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '219', 'type': 'argument_list', 'children': []}; {'id': '220', 'type': 'return_statement', 'children': ['221']}, {'id': '221', 'type': 'True', 'children': []}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'match'}, {'id': '229', 'type': 'argument_list', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'expect'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '232', 'type': 'if_statement', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '234', 'type': 'block', 'children': ['235', '266', '275', '301']}, {'id': '235', 'type': 'if_statement', 'children': ['236', '244']}; {'id': '236', 'type': 'comparison_operator', 'children': ['237', '243'], 'value': 'in'}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'OTGW_ERRS'}; {'id': '244', 'type': 'block', 'children': ['245', '259', '265']}, {'id': '245', 'type': 'if_statement', 'children': ['246', '249']}; {'id': '246', 'type': 'comparison_operator', 'children': ['247', '248'], 'value': '=='}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'retry'}; {'id': '248', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '249', 'type': 'block', 'children': ['250']}; {'id': '250', 'type': 'raise_statement', 'children': ['251']}, {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'OTGW_ERRS'}, {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'await', 'children': ['261']}, {'id': '261', 'type': 'call', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'send_again'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '265', 'type': 'return_statement', 'children': []}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'group'}, {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '275', 'type': 'if_statement', 'children': ['276', '283']}; {'id': '276', 'type': 'boolean_operator', 'children': ['277', '280'], 'value': 'and'}, {'id': '277', 'type': 'comparison_operator', 'children': ['278', '279'], 'value': '=='}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'OTGW_CMD_SUMMARY'}; {'id': '280', 'type': 'comparison_operator', 'children': ['281', '282'], 'value': '=='}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '282', 'type': 'string', 'children': [], 'value': "'1'"}, {'id': '283', 'type': 'block', 'children': ['284', '295']}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'assignment', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'part2'}, {'id': '287', 'type': 'await', 'children': ['288']}; {'id': '288', 'type': 'call', 'children': ['289', '294']}, {'id': '289', 'type': 'attribute', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': '_cmdq'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '294', 'type': 'argument_list', 'children': []}, {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'assignment', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '298', 'type': 'list', 'children': ['299', '300'], 'value': '[ret, part2]'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'part2'}, {'id': '301', 'type': 'return_statement', 'children': ['302']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '303', 'type': 'if_statement', 'children': ['304', '311']}; {'id': '304', 'type': 'call', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '308', 'type': 'argument_list', 'children': ['309', '310']}, {'id': '309', 'type': 'string', 'children': [], 'value': "r'Error 0[1-4]'"}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '311', 'type': 'block', 'children': ['312', '323']}; {'id': '312', 'type': 'expression_statement', 'children': ['313']}, {'id': '313', 'type': 'call', 'children': ['314', '317']}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': '_LOGGER'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '317', 'type': 'argument_list', 'children': ['318', '322']}; {'id': '318', 'type': 'concatenated_string', 'children': ['319', '320', '321']}, {'id': '319', 'type': 'string', 'children': [], 'value': '"Received %s. If this happens during a "'}; {'id': '320', 'type': 'string', 'children': [], 'value': '"reset of the gateway it can be safely "'}, {'id': '321', 'type': 'string', 'children': [], 'value': '"ignored."'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '323', 'type': 'return_statement', 'children': []}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}, {'id': '325', 'type': 'call', 'children': ['326', '329']}; {'id': '326', 'type': 'attribute', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': '_LOGGER'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '329', 'type': 'argument_list', 'children': ['330', '331']}; {'id': '330', 'type': 'string', 'children': [], 'value': '"Unknown message in command queue: %s"'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}, {'id': '333', 'type': 'await', 'children': ['334']}; {'id': '334', 'type': 'call', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'send_again'}; {'id': '336', 'type': 'argument_list', 'children': ['337']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '338', 'type': 'while_statement', 'children': ['339', '340']}, {'id': '339', 'type': 'True', 'children': []}; {'id': '340', 'type': 'block', 'children': ['341', '352', '360']}, {'id': '341', 'type': 'expression_statement', 'children': ['342']}; {'id': '342', 'type': 'assignment', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '344', 'type': 'await', 'children': ['345']}, {'id': '345', 'type': 'call', 'children': ['346', '351']}; {'id': '346', 'type': 'attribute', 'children': ['347', '350']}, {'id': '347', 'type': 'attribute', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': '_cmdq'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '351', 'type': 'argument_list', 'children': []}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}, {'id': '353', 'type': 'assignment', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '355', 'type': 'await', 'children': ['356']}; {'id': '356', 'type': 'call', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '358', 'type': 'argument_list', 'children': ['359']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '360', 'type': 'if_statement', 'children': ['361', '364']}, {'id': '361', 'type': 'comparison_operator', 'children': ['362', '363'], 'value': 'is'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '363', 'type': 'None', 'children': []}; {'id': '364', 'type': 'block', 'children': ['365']}, {'id': '365', 'type': 'return_statement', 'children': ['366']} | async def issue_cmd(self, cmd, value, retry=3):
async with self._cmd_lock:
if not self.connected:
_LOGGER.debug(
"Serial transport closed, not sending command %s", cmd)
return
while not self._cmdq.empty():
_LOGGER.debug("Clearing leftover message from command queue:"
" %s", await self._cmdq.get())
_LOGGER.debug("Sending command: %s with value %s", cmd, value)
self.transport.write(
'{}={}\r\n'.format(cmd, value).encode('ascii'))
if cmd == OTGW_CMD_REPORT:
expect = r'^{}:\s*([A-Z]{{2}}|{}=[^$]+)$'.format(cmd, value)
else:
expect = r'^{}:\s*([^$]+)$'.format(cmd)
async def send_again(err):
nonlocal retry
_LOGGER.warning("Command %s failed with %s, retrying...", cmd,
err)
retry -= 1
self.transport.write(
'{}={}\r\n'.format(cmd, value).encode('ascii'))
async def process(msg):
_LOGGER.debug("Got possible response for command %s: %s", cmd,
msg)
if msg in OTGW_ERRS:
if retry == 0:
raise OTGW_ERRS[msg]
await send_again(msg)
return
if cmd == OTGW_CMD_MODE and value == 'R':
while not re.match(
r'OpenTherm Gateway \d+\.\d+\.\d+', msg):
msg = await self._cmdq.get()
return True
match = re.match(expect, msg)
if match:
if match.group(1) in OTGW_ERRS:
if retry == 0:
raise OTGW_ERRS[match.group(1)]
await send_again(msg)
return
ret = match.group(1)
if cmd == OTGW_CMD_SUMMARY and ret == '1':
part2 = await self._cmdq.get()
ret = [ret, part2]
return ret
if re.match(r'Error 0[1-4]', msg):
_LOGGER.warning("Received %s. If this happens during a "
"reset of the gateway it can be safely "
"ignored.", msg)
return
_LOGGER.warning("Unknown message in command queue: %s", msg)
await send_again(msg)
while True:
msg = await self._cmdq.get()
ret = await process(msg)
if ret is not None:
return ret |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_reports'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '14', '55', '115', '124', '150', '159', '187', '196', '238', '247', '275', '284', '302', '311', '329', '354', '361']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'OTGW_CMD_REPORT'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'reports'}, {'id': '13', 'type': 'dictionary', 'children': []}; {'id': '14', 'type': 'for_statement', 'children': ['15', '16', '21']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORTS'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '33', '45']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '25', 'type': 'await', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_wait_for_cmd'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'block', 'children': ['38', '44']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '43']}; {'id': '40', 'type': 'subscript', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'reports'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'continue_statement', 'children': []}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '50']}, {'id': '47', 'type': 'subscript', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'reports'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '52', 'type': 'slice', 'children': ['53', '54']}, {'id': '53', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '54', 'type': 'colon', 'children': []}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '58', 'type': 'dictionary', 'children': ['59', '67', '75', '83', '91', '99', '107']}, {'id': '59', 'type': 'pair', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'OTGW_ABOUT'}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'reports'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_ABOUT'}, {'id': '67', 'type': 'pair', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'OTGW_BUILD'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'reports'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_BUILDDATE'}, {'id': '75', 'type': 'pair', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'OTGW_CLOCKMHZ'}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'reports'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_CLOCKMHZ'}, {'id': '83', 'type': 'pair', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'OTGW_MODE'}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'reports'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_GW_MODE'}, {'id': '91', 'type': 'pair', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'OTGW_SMART_PWR'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'reports'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_SMART_PWR'}, {'id': '99', 'type': 'pair', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'OTGW_THRM_DETECT'}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'reports'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_THERMOSTAT_DETECT'}, {'id': '107', 'type': 'pair', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'OTGW_DHW_OVRD'}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'reports'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_DHW_SETTING'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'ovrd_mode'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'reports'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_SETPOINT_OVRD'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '128']}, {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ovrd_mode'}, {'id': '127', 'type': 'None', 'children': []}; {'id': '128', 'type': 'block', 'children': ['129', '140']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'ovrd_mode'}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'ovrd_mode'}, {'id': '139', 'type': 'integer', 'children': [], 'value': '0'}; {'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': 'status'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'dictionary', 'children': ['147']}, {'id': '147', 'type': 'pair', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'OTGW_SETP_OVRD_MODE'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'ovrd_mode'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'gpio_funcs'}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'reports'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_GPIO_FUNCS'}, {'id': '159', 'type': 'if_statement', 'children': ['160', '163']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': 'is'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'gpio_funcs'}; {'id': '162', 'type': 'None', 'children': []}, {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'dictionary', 'children': ['171', '179']}, {'id': '171', 'type': 'pair', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'OTGW_GPIO_A'}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'gpio_funcs'}; {'id': '178', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '179', 'type': 'pair', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'OTGW_GPIO_B'}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'gpio_funcs'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'led_funcs'}; {'id': '190', 'type': 'call', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'reports'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_LED_FUNCS'}; {'id': '196', 'type': 'if_statement', 'children': ['197', '200']}, {'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': 'is'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'led_funcs'}, {'id': '199', 'type': 'None', 'children': []}; {'id': '200', 'type': 'block', 'children': ['201']}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'dictionary', 'children': ['208', '213', '218', '223', '228', '233']}; {'id': '208', 'type': 'pair', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'OTGW_LED_A'}; {'id': '210', 'type': 'subscript', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'led_funcs'}; {'id': '212', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '213', 'type': 'pair', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'OTGW_LED_B'}, {'id': '215', 'type': 'subscript', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'led_funcs'}, {'id': '217', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '218', 'type': 'pair', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'OTGW_LED_C'}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'led_funcs'}; {'id': '222', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '223', 'type': 'pair', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'OTGW_LED_D'}, {'id': '225', 'type': 'subscript', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'led_funcs'}, {'id': '227', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '228', 'type': 'pair', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'OTGW_LED_E'}; {'id': '230', 'type': 'subscript', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'led_funcs'}; {'id': '232', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '233', 'type': 'pair', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'OTGW_LED_F'}, {'id': '235', 'type': 'subscript', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'led_funcs'}, {'id': '237', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'assignment', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'tweaks'}, {'id': '241', 'type': 'call', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'reports'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_TWEAKS'}, {'id': '247', 'type': 'if_statement', 'children': ['248', '251']}; {'id': '248', 'type': 'comparison_operator', 'children': ['249', '250'], 'value': 'is'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'tweaks'}; {'id': '250', 'type': 'None', 'children': []}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'dictionary', 'children': ['259', '267']}, {'id': '259', 'type': 'pair', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'OTGW_IGNORE_TRANSITIONS'}, {'id': '261', 'type': 'call', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'subscript', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'tweaks'}; {'id': '266', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '267', 'type': 'pair', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'OTGW_OVRD_HB'}, {'id': '269', 'type': 'call', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'subscript', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'tweaks'}; {'id': '274', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'sb_temp'}; {'id': '278', 'type': 'call', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'reports'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_SETBACK_TEMP'}; {'id': '284', 'type': 'if_statement', 'children': ['285', '288']}, {'id': '285', 'type': 'comparison_operator', 'children': ['286', '287'], 'value': 'is'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'sb_temp'}, {'id': '287', 'type': 'None', 'children': []}; {'id': '288', 'type': 'block', 'children': ['289']}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'call', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}, {'id': '295', 'type': 'dictionary', 'children': ['296']}; {'id': '296', 'type': 'pair', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'OTGW_SB_TEMP'}; {'id': '298', 'type': 'call', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'sb_temp'}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'assignment', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'vref'}, {'id': '305', 'type': 'call', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'reports'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_VREF'}, {'id': '311', 'type': 'if_statement', 'children': ['312', '315']}; {'id': '312', 'type': 'comparison_operator', 'children': ['313', '314'], 'value': 'is'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'vref'}; {'id': '314', 'type': 'None', 'children': []}, {'id': '315', 'type': 'block', 'children': ['316']}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'call', 'children': ['318', '321']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'dictionary', 'children': ['323']}, {'id': '323', 'type': 'pair', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'OTGW_VREF'}, {'id': '325', 'type': 'call', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '327', 'type': 'argument_list', 'children': ['328']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'vref'}, {'id': '329', 'type': 'if_statement', 'children': ['330', '338']}; {'id': '330', 'type': 'parenthesized_expression', 'children': ['331'], 'value': '()'}, {'id': '331', 'type': 'boolean_operator', 'children': ['332', '335'], 'value': 'and'}; {'id': '332', 'type': 'comparison_operator', 'children': ['333', '334'], 'value': 'is'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'ovrd_mode'}; {'id': '334', 'type': 'None', 'children': []}, {'id': '335', 'type': 'comparison_operator', 'children': ['336', '337'], 'value': '!='}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'ovrd_mode'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'OTGW_SETP_OVRD_DISABLED'}; {'id': '338', 'type': 'block', 'children': ['339']}, {'id': '339', 'type': 'expression_statement', 'children': ['340']}; {'id': '340', 'type': 'assignment', 'children': ['341', '344']}, {'id': '341', 'type': 'subscript', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'DATA_ROOM_SETPOINT_OVRD'}; {'id': '344', 'type': 'call', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '346', 'type': 'argument_list', 'children': ['347']}, {'id': '347', 'type': 'subscript', 'children': ['348', '351']}; {'id': '348', 'type': 'subscript', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'reports'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'OTGW_REPORT_SETPOINT_OVRD'}, {'id': '351', 'type': 'slice', 'children': ['352', '353']}; {'id': '352', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '353', 'type': 'colon', 'children': []}; {'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': 'self'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': '_update_status'}, {'id': '359', 'type': 'argument_list', 'children': ['360']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '361', 'type': 'return_statement', 'children': ['362']}; {'id': '362', 'type': 'call', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '364', 'type': 'argument_list', 'children': ['365']}, {'id': '365', 'type': 'attribute', 'children': ['366', '369']}; {'id': '366', 'type': 'attribute', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': '_protocol'}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'status'} | async def get_reports(self):
cmd = OTGW_CMD_REPORT
reports = {}
for value in OTGW_REPORTS.keys():
ret = await self._wait_for_cmd(cmd, value)
if ret is None:
reports[value] = None
continue
reports[value] = ret[2:]
status = {
OTGW_ABOUT: reports.get(OTGW_REPORT_ABOUT),
OTGW_BUILD: reports.get(OTGW_REPORT_BUILDDATE),
OTGW_CLOCKMHZ: reports.get(OTGW_REPORT_CLOCKMHZ),
OTGW_MODE: reports.get(OTGW_REPORT_GW_MODE),
OTGW_SMART_PWR: reports.get(OTGW_REPORT_SMART_PWR),
OTGW_THRM_DETECT: reports.get(OTGW_REPORT_THERMOSTAT_DETECT),
OTGW_DHW_OVRD: reports.get(OTGW_REPORT_DHW_SETTING),
}
ovrd_mode = reports.get(OTGW_REPORT_SETPOINT_OVRD)
if ovrd_mode is not None:
ovrd_mode = str.upper(ovrd_mode[0])
status.update({OTGW_SETP_OVRD_MODE: ovrd_mode})
gpio_funcs = reports.get(OTGW_REPORT_GPIO_FUNCS)
if gpio_funcs is not None:
status.update({
OTGW_GPIO_A: int(gpio_funcs[0]),
OTGW_GPIO_B: int(gpio_funcs[1]),
})
led_funcs = reports.get(OTGW_REPORT_LED_FUNCS)
if led_funcs is not None:
status.update({
OTGW_LED_A: led_funcs[0],
OTGW_LED_B: led_funcs[1],
OTGW_LED_C: led_funcs[2],
OTGW_LED_D: led_funcs[3],
OTGW_LED_E: led_funcs[4],
OTGW_LED_F: led_funcs[5],
})
tweaks = reports.get(OTGW_REPORT_TWEAKS)
if tweaks is not None:
status.update({
OTGW_IGNORE_TRANSITIONS: int(tweaks[0]),
OTGW_OVRD_HB: int(tweaks[1]),
})
sb_temp = reports.get(OTGW_REPORT_SETBACK_TEMP)
if sb_temp is not None:
status.update({OTGW_SB_TEMP: float(sb_temp)})
vref = reports.get(OTGW_REPORT_VREF)
if vref is not None:
status.update({OTGW_VREF: int(vref)})
if (ovrd_mode is not None and ovrd_mode != OTGW_SETP_OVRD_DISABLED):
status[DATA_ROOM_SETPOINT_OVRD] = float(
reports[OTGW_REPORT_SETPOINT_OVRD][1:])
self._update_status(status)
return dict(self._protocol.status) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'nobuild'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'usecache'}, {'id': '11', 'type': 'True', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'pull'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '33', '41', '57', '77', '93', '227', '233']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '19']}, {'id': '17', 'type': 'not_operator', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'nobuild'}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'update_source_images'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27', '30']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'client'}, {'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'usecache'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'usecache'}; {'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'pull'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'pull'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'utils'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'get_console_width'}; {'id': '40', 'type': 'argument_list', 'children': []}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'cprint'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '50', '53']}, {'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '+'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '*'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'='"}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '50', 'type': 'keyword_argument', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'white'"}, {'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '55', 'type': 'list', 'children': ['56'], 'value': "['bold']"}; {'id': '56', 'type': 'string', 'children': [], 'value': "'bold'"}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '%'}, {'id': '61', 'type': 'string', 'children': [], 'value': '\'STARTING BUILD for "%s" (image definition "%s" from %s)\\n\''}; {'id': '62', 'type': 'tuple', 'children': ['63', '66', '69']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'targetname'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'imagename'}, {'id': '69', 'type': 'attribute', 'children': ['70', '76']}; {'id': '70', 'type': 'subscript', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'steps'}; {'id': '74', 'type': 'unary_operator', 'children': ['75'], 'value': '-'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sourcefile'}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'cprint'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '86', '89']}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': '_centered'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'blue'"}, {'id': '89', 'type': 'keyword_argument', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '91', 'type': 'list', 'children': ['92'], 'value': "['bold']"}; {'id': '92', 'type': 'string', 'children': [], 'value': "'bold'"}, {'id': '93', 'type': 'for_statement', 'children': ['94', '97', '103']}; {'id': '94', 'type': 'pattern_list', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'istep'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'step'}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'steps'}, {'id': '103', 'type': 'block', 'children': ['104', '153']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '113', '133', '140']}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'colored'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112']}, {'id': '111', 'type': 'string', 'children': [], 'value': "'* Step'"}; {'id': '112', 'type': 'string', 'children': [], 'value': "'blue'"}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'colored'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '128', '129']}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '%'}, {'id': '117', 'type': 'string', 'children': [], 'value': "'%d/%d'"}; {'id': '118', 'type': 'tuple', 'children': ['119', '122']}, {'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '+'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'istep'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'steps'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'blue'"}, {'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '131', 'type': 'list', 'children': ['132'], 'value': "['bold']"}; {'id': '132', 'type': 'string', 'children': [], 'value': "'bold'"}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'colored'}, {'id': '135', 'type': 'argument_list', 'children': ['136', '137']}; {'id': '136', 'type': 'string', 'children': [], 'value': "'for image'"}, {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'color'}, {'id': '139', 'type': 'string', 'children': [], 'value': "'blue'"}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'colored'}; {'id': '142', 'type': 'argument_list', 'children': ['143', '146', '149']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'imagename'}; {'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'blue'"}, {'id': '149', 'type': 'keyword_argument', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '151', 'type': 'list', 'children': ['152'], 'value': "['bold']"}; {'id': '152', 'type': 'string', 'children': [], 'value': "'bold'"}, {'id': '153', 'type': 'if_statement', 'children': ['154', '156']}; {'id': '154', 'type': 'not_operator', 'children': ['155']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'nobuild'}; {'id': '156', 'type': 'block', 'children': ['157', '182', '192', '215']}, {'id': '157', 'type': 'if_statement', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'step'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'bust_cache'}, {'id': '161', 'type': 'block', 'children': ['162', '171']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'stackkey'}, {'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': '_get_stack_key'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'istep'}, {'id': '171', 'type': 'if_statement', 'children': ['172', '175']}; {'id': '172', 'type': 'comparison_operator', 'children': ['173', '174'], 'value': 'in'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'stackkey'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': '_rebuilt'}, {'id': '175', 'type': 'block', 'children': ['176']}; {'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': 'step'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'bust_cache'}, {'id': '181', 'type': 'False', 'children': []}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'step'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'build'}, {'id': '187', 'type': 'argument_list', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'client'}, {'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'usecache'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'usecache'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '195', 'type': 'argument_list', 'children': ['196', '201', '212']}; {'id': '196', 'type': 'call', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'colored'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '200']}, {'id': '199', 'type': 'string', 'children': [], 'value': '"* Created intermediate image"'}; {'id': '200', 'type': 'string', 'children': [], 'value': "'green'"}, {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'colored'}, {'id': '203', 'type': 'argument_list', 'children': ['204', '207', '208']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'step'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'buildname'}, {'id': '207', 'type': 'string', 'children': [], 'value': "'green'"}; {'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '210', 'type': 'list', 'children': ['211'], 'value': "['bold']"}, {'id': '211', 'type': 'string', 'children': [], 'value': "'bold'"}; {'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'\\n\\n'"}, {'id': '215', 'type': 'if_statement', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'step'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'bust_cache'}, {'id': '219', 'type': 'block', 'children': ['220']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'call', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': '_rebuilt'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'stackkey'}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'finalimage'}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'step'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'buildname'}, {'id': '233', 'type': 'if_statement', 'children': ['234', '236']}; {'id': '234', 'type': 'not_operator', 'children': ['235']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'nobuild'}; {'id': '236', 'type': 'block', 'children': ['237', '245', '265', '281']}, {'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': 'self'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'finalizenames'}; {'id': '242', 'type': 'argument_list', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'client'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'finalimage'}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '%'}, {'id': '249', 'type': 'string', 'children': [], 'value': '\'FINISHED BUILDING "%s" (image definition "%s" from %s)\''}; {'id': '250', 'type': 'tuple', 'children': ['251', '254', '257']}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'targetname'}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'imagename'}, {'id': '257', 'type': 'attribute', 'children': ['258', '264']}; {'id': '258', 'type': 'subscript', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'steps'}; {'id': '262', 'type': 'unary_operator', 'children': ['263'], 'value': '-'}, {'id': '263', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'sourcefile'}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'call', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'cprint'}; {'id': '268', 'type': 'argument_list', 'children': ['269', '274', '277']}, {'id': '269', 'type': 'call', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': '_centered'}, {'id': '271', 'type': 'argument_list', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '276', 'type': 'string', 'children': [], 'value': "'green'"}, {'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '279', 'type': 'list', 'children': ['280'], 'value': "['bold']"}; {'id': '280', 'type': 'string', 'children': [], 'value': "'bold'"}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'call', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'cprint'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '288', '291', '295']}, {'id': '285', 'type': 'binary_operator', 'children': ['286', '287'], 'value': '*'}; {'id': '286', 'type': 'string', 'children': [], 'value': "'='"}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '288', 'type': 'keyword_argument', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '290', 'type': 'string', 'children': [], 'value': "'white'"}, {'id': '291', 'type': 'keyword_argument', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '293', 'type': 'list', 'children': ['294'], 'value': "['bold']"}; {'id': '294', 'type': 'string', 'children': [], 'value': "'bold'"}, {'id': '295', 'type': 'keyword_argument', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '297', 'type': 'string', 'children': [], 'value': "'\\n\\n'"} | def build(self, client,
nobuild=False,
usecache=True,
pull=False):
if not nobuild:
self.update_source_images(client,
usecache=usecache,
pull=pull)
width = utils.get_console_width()
cprint('\n' + '='*width,
color='white', attrs=['bold'])
line = 'STARTING BUILD for "%s" (image definition "%s" from %s)\n' % (
self.targetname, self.imagename, self.steps[-1].sourcefile)
cprint(_centered(line, width), color='blue', attrs=['bold'])
for istep, step in enumerate(self.steps):
print(colored('* Step','blue'),
colored('%d/%d' % (istep+1, len(self.steps)), 'blue', attrs=['bold']),
colored('for image', color='blue'),
colored(self.imagename, color='blue', attrs=['bold']))
if not nobuild:
if step.bust_cache:
stackkey = self._get_stack_key(istep)
if stackkey in _rebuilt:
step.bust_cache = False
step.build(client, usecache=usecache)
print(colored("* Created intermediate image", 'green'),
colored(step.buildname, 'green', attrs=['bold']),
end='\n\n')
if step.bust_cache:
_rebuilt.add(stackkey)
finalimage = step.buildname
if not nobuild:
self.finalizenames(client, finalimage)
line = 'FINISHED BUILDING "%s" (image definition "%s" from %s)'%(
self.targetname, self.imagename, self.steps[-1].sourcefile)
cprint(_centered(line, width),
color='green', attrs=['bold'])
cprint('=' * width, color='white', attrs=['bold'], end='\n\n') |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_check_yaml_and_paths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ymlfilepath'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'yamldefs'}; {'id': '6', 'type': 'block', 'children': ['7', '18', '29', '47']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'relpath'}; {'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': 'os'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'relpath'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ymlfilepath'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'not'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'relpath'}; {'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': 'relpath'}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '%'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'./%s'"}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'relpath'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'pathroot'}; {'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': 'abspath'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'dirname'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'ymlfilepath'}, {'id': '47', 'type': 'for_statement', 'children': ['48', '51', '55']}; {'id': '48', 'type': 'pattern_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'imagename'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'defn'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'yamldefs'}, {'id': '55', 'type': 'block', 'children': ['56', '91', '115', '186', '192', '212', '235', '263']}; {'id': '56', 'type': 'if_statement', 'children': ['57', '60', '85']}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': '=='}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'imagename'}, {'id': '59', 'type': 'string', 'children': [], 'value': "'_SOURCES_'"}; {'id': '60', 'type': 'block', 'children': ['61', '84']}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '66']}, {'id': '63', 'type': 'subscript', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'yamldefs'}, {'id': '65', 'type': 'string', 'children': [], 'value': "'_SOURCES_'"}; {'id': '66', 'type': 'list_comprehension', 'children': ['67', '79']}, {'id': '67', 'type': 'call', 'children': ['68', '73']}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'relpath'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': '_get_abspath'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'pathroot'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '79', 'type': 'for_in_clause', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'yamldefs'}, {'id': '83', 'type': 'string', 'children': [], 'value': "'_SOURCES_'"}; {'id': '84', 'type': 'continue_statement', 'children': []}, {'id': '85', 'type': 'elif_clause', 'children': ['86', '89']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'in'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'imagename'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'SPECIAL_FIELDS'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'continue_statement', 'children': []}, {'id': '91', 'type': 'for_statement', 'children': ['92', '93', '97']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '93', 'type': 'tuple', 'children': ['94', '95', '96']}; {'id': '94', 'type': 'string', 'children': [], 'value': "'build_directory'"}, {'id': '95', 'type': 'string', 'children': [], 'value': "'FROM_DOCKERFILE'"}; {'id': '96', 'type': 'string', 'children': [], 'value': "'ignorefile'"}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'if_statement', 'children': ['99', '102']}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'in'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'defn'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'defn'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': '_get_abspath'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'pathroot'}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'defn'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '115', 'type': 'if_statement', 'children': ['116', '119']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'in'}, {'id': '117', 'type': 'string', 'children': [], 'value': "'copy_from'"}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'defn'}, {'id': '119', 'type': 'block', 'children': ['120', '146']}; {'id': '120', 'type': 'if_statement', 'children': ['121', '129']}, {'id': '121', 'type': 'not_operator', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '128']}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'defn'}, {'id': '127', 'type': 'string', 'children': [], 'value': "'copy_from'"}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'raise_statement', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ParsingFailure'}, {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '143'], 'value': '%'}, {'id': '137', 'type': 'parenthesized_expression', 'children': ['138'], 'value': '()'}; {'id': '138', 'type': 'binary_operator', 'children': ['139', '140'], 'value': '+'}, {'id': '139', 'type': 'string', 'children': [], 'value': '\'Syntax error in file "%s": \\n\''}; {'id': '140', 'type': 'concatenated_string', 'children': ['141', '142']}, {'id': '141', 'type': 'string', 'children': [], 'value': '\'The "copy_from" field in image definition "%s" is not \\n\''}; {'id': '142', 'type': 'string', 'children': [], 'value': "'a key:value list.'"}, {'id': '143', 'type': 'tuple', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ymlfilepath'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'imagename'}; {'id': '146', 'type': 'for_statement', 'children': ['147', '150', '161']}, {'id': '147', 'type': 'pattern_list', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'otherimg'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '150', 'type': 'call', 'children': ['151', '160']}, {'id': '151', 'type': 'attribute', 'children': ['152', '159']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'defn'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '158']}, {'id': '157', 'type': 'string', 'children': [], 'value': "'copy_from'"}; {'id': '158', 'type': 'dictionary', 'children': []}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '160', 'type': 'argument_list', 'children': []}, {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'if_statement', 'children': ['163', '169']}, {'id': '163', 'type': 'not_operator', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'raise_statement', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'ParsingFailure'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '182'], 'value': '%'}, {'id': '177', 'type': 'parenthesized_expression', 'children': ['178'], 'value': '()'}; {'id': '178', 'type': 'concatenated_string', 'children': ['179', '180', '181']}, {'id': '179', 'type': 'string', 'children': [], 'value': "'Syntax error in field:\\n'"}; {'id': '180', 'type': 'string', 'children': [], 'value': '\' %s . copy_from . %s\\nin file "%s". \\n\''}, {'id': '181', 'type': 'string', 'children': [], 'value': '\'All entries must be of the form "sourcepath: destpath"\''}; {'id': '182', 'type': 'tuple', 'children': ['183', '184', '185']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'imagename'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'otherimg'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'ymlfilepath'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '191']}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'defn'}; {'id': '190', 'type': 'string', 'children': [], 'value': "'_sourcefile'"}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'relpath'}; {'id': '192', 'type': 'if_statement', 'children': ['193', '200']}, {'id': '193', 'type': 'boolean_operator', 'children': ['194', '197'], 'value': 'and'}; {'id': '194', 'type': 'comparison_operator', 'children': ['195', '196'], 'value': 'in'}, {'id': '195', 'type': 'string', 'children': [], 'value': "'ignore'"}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'defn'}, {'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': 'in'}; {'id': '198', 'type': 'string', 'children': [], 'value': "'ignorefile'"}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'defn'}; {'id': '200', 'type': 'block', 'children': ['201']}, {'id': '201', 'type': 'raise_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'MultipleIgnoreError'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'binary_operator', 'children': ['208', '211'], 'value': '+'}; {'id': '208', 'type': 'binary_operator', 'children': ['209', '210'], 'value': '%'}, {'id': '209', 'type': 'string', 'children': [], 'value': '\'Image "%s" has both "ignore" AND "ignorefile" fields.\''}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'imagename'}, {'id': '211', 'type': 'string', 'children': [], 'value': "' At most ONE of these should be defined'"}; {'id': '212', 'type': 'if_statement', 'children': ['213', '225']}, {'id': '213', 'type': 'boolean_operator', 'children': ['214', '217'], 'value': 'and'}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': 'in'}, {'id': '215', 'type': 'string', 'children': [], 'value': "'secret_files'"}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'defn'}, {'id': '217', 'type': 'not_operator', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'defn'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '224']}, {'id': '223', 'type': 'string', 'children': [], 'value': "'squash'"}; {'id': '224', 'type': 'True', 'children': []}, {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'raise_statement', 'children': ['227']}, {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'ParsingFailure'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'binary_operator', 'children': ['233', '234'], 'value': '%'}, {'id': '233', 'type': 'string', 'children': [], 'value': '"Step \'%s\' defines secret_files, so \'squash\' cannot be set to \'false\'"'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'imagename'}, {'id': '235', 'type': 'if_statement', 'children': ['236', '251']}; {'id': '236', 'type': 'boolean_operator', 'children': ['237', '244'], 'value': 'and'}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'defn'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '241', 'type': 'argument_list', 'children': ['242', '243']}; {'id': '242', 'type': 'string', 'children': [], 'value': "'secret_files'"}, {'id': '243', 'type': 'None', 'children': []}; {'id': '244', 'type': 'call', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'defn'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '248', 'type': 'argument_list', 'children': ['249', '250']}, {'id': '249', 'type': 'string', 'children': [], 'value': "'copy_from'"}; {'id': '250', 'type': 'False', 'children': []}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'raise_statement', 'children': ['253']}, {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'ParsingFailure'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'binary_operator', 'children': ['259', '262'], 'value': '%'}, {'id': '259', 'type': 'concatenated_string', 'children': ['260', '261']}; {'id': '260', 'type': 'string', 'children': [], 'value': "'`secret_files` currently is not implmemented to handle `copy_from`'"}, {'id': '261', 'type': 'string', 'children': [], 'value': "' (step %s)'"}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'imagename'}, {'id': '263', 'type': 'for_statement', 'children': ['264', '265', '266']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'defn'}; {'id': '266', 'type': 'block', 'children': ['267']}, {'id': '267', 'type': 'if_statement', 'children': ['268', '271']}; {'id': '268', 'type': 'comparison_operator', 'children': ['269', '270'], 'value': 'not'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'RECOGNIZED_KEYS'}, {'id': '271', 'type': 'block', 'children': ['272']}; {'id': '272', 'type': 'raise_statement', 'children': ['273']}, {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'UnrecognizedKeyError'}, {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'binary_operator', 'children': ['279', '280'], 'value': '%'}, {'id': '279', 'type': 'string', 'children': [], 'value': '\'Field "%s" in image "%s" in file "%s" not recognized\''}; {'id': '280', 'type': 'tuple', 'children': ['281', '282', '283']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'imagename'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'relpath'} | def _check_yaml_and_paths(ymlfilepath, yamldefs):
relpath = os.path.relpath(ymlfilepath)
if '/' not in relpath:
relpath = './%s' % relpath
pathroot = os.path.abspath(os.path.dirname(ymlfilepath))
for imagename, defn in iteritems(yamldefs):
if imagename == '_SOURCES_':
yamldefs['_SOURCES_'] = [os.path.relpath(_get_abspath(pathroot, p))
for p in yamldefs['_SOURCES_']]
continue
elif imagename in SPECIAL_FIELDS:
continue
for key in ('build_directory', 'FROM_DOCKERFILE', 'ignorefile'):
if key in defn:
defn[key] = _get_abspath(pathroot, defn[key])
if 'copy_from' in defn:
if not isinstance(defn['copy_from'], dict):
raise errors.ParsingFailure((
'Syntax error in file "%s": \n' +
'The "copy_from" field in image definition "%s" is not \n'
'a key:value list.') % (ymlfilepath, imagename))
for otherimg, value in defn.get('copy_from', {}).items():
if not isinstance(value, dict):
raise errors.ParsingFailure((
'Syntax error in field:\n'
' %s . copy_from . %s\nin file "%s". \n'
'All entries must be of the form "sourcepath: destpath"')%
(imagename, otherimg, ymlfilepath))
defn['_sourcefile'] = relpath
if 'ignore' in defn and 'ignorefile' in defn:
raise errors.MultipleIgnoreError(
'Image "%s" has both "ignore" AND "ignorefile" fields.' % imagename +
' At most ONE of these should be defined')
if 'secret_files' in defn and not defn.get('squash', True):
raise errors.ParsingFailure(
"Step '%s' defines secret_files, so 'squash' cannot be set to 'false'"
% imagename)
if defn.get('secret_files', None) and defn.get('copy_from', False):
raise errors.ParsingFailure(
'`secret_files` currently is not implmemented to handle `copy_from`'
' (step %s)' % imagename)
for key in defn:
if key not in RECOGNIZED_KEYS:
raise errors.UnrecognizedKeyError(
'Field "%s" in image "%s" in file "%s" not recognized' %
(key, imagename, relpath)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_build'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'targetname'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'rebuilds'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'cache_repo'}; {'id': '12', 'type': 'string', 'children': [], 'value': "''"}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'cache_tag'}, {'id': '15', 'type': 'string', 'children': [], 'value': "''"}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'buildargs'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'dictionary_splat_pattern', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '21', 'type': 'block', 'children': ['22', '31', '53', '67', '94', '98', '102', '108', '126', '313', '335']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'from_image'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_external_base_image'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'image'}, {'id': '31', 'type': 'if_statement', 'children': ['32', '35', '47']}; {'id': '32', 'type': 'boolean_operator', 'children': ['33', '34'], 'value': 'or'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cache_repo'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'cache_tag'}, {'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': 'cache_from'}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'utils'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'generate_name'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45', '46']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'image'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'cache_repo'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'cache_tag'}, {'id': '47', 'type': 'else_clause', 'children': ['48']}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'cache_from'}; {'id': '52', 'type': 'None', 'children': []}, {'id': '53', 'type': 'if_statement', 'children': ['54', '57']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'from_image'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'raise_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'NoBaseError'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '%'}, {'id': '65', 'type': 'string', 'children': [], 'value': '"No base image found in %s\'s dependencies"'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'image'}, {'id': '67', 'type': 'if_statement', 'children': ['68', '73', '84']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'from_image'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ExternalDockerfile'}, {'id': '73', 'type': 'block', 'children': ['74', '78']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'build_first'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'from_image'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'base_image'}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'from_image'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '84', 'type': 'else_clause', 'children': ['85']}, {'id': '85', 'type': 'block', 'children': ['86', '90']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'base_image'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'from_image'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'build_first'}, {'id': '93', 'type': 'None', 'children': []}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'build_steps'}, {'id': '97', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'istep'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'sourceimages'}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '107', 'type': 'argument_list', 'children': []}; {'id': '108', 'type': 'if_statement', 'children': ['109', '112', '117']}, {'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'is'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'rebuilds'}, {'id': '111', 'type': 'None', 'children': []}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'rebuilds'}; {'id': '116', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '117', 'type': 'else_clause', 'children': ['118']}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'rebuilds'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'rebuilds'}; {'id': '126', 'type': 'for_statement', 'children': ['127', '128', '134']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'base_name'}; {'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': 'sort_dependencies'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '134', 'type': 'block', 'children': ['135', '139', '147', '161', '178', '219', '223', '227']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'augmented_assignment', 'children': ['137', '138'], 'value': '+='}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'istep'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'buildname'}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '144'], 'value': '%'}, {'id': '143', 'type': 'string', 'children': [], 'value': "'dmkbuild_%s_%d'"}; {'id': '144', 'type': 'tuple', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'istep'}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'secret_files'}; {'id': '150', 'type': 'call', 'children': ['151', '158']}, {'id': '151', 'type': 'attribute', 'children': ['152', '157']}; {'id': '152', 'type': 'subscript', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'ymldefs'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'base_name'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '160']}, {'id': '159', 'type': 'string', 'children': [], 'value': "'secret_files'"}; {'id': '160', 'type': 'None', 'children': []}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'squash'}; {'id': '164', 'type': 'call', 'children': ['165', '172']}, {'id': '165', 'type': 'attribute', 'children': ['166', '171']}; {'id': '166', 'type': 'subscript', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ymldefs'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'base_name'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174']}, {'id': '173', 'type': 'string', 'children': [], 'value': "'squash'"}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'secret_files'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'build_steps'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'append'}, {'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': 'dockermake'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'step'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'BuildStep'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '192', '193', '198', '199', '204', '207', '210', '213', '216']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'base_name'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'base_image'}, {'id': '193', 'type': 'subscript', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'ymldefs'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'base_name'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'buildname'}, {'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'bust_cache'}, {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': 'in'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'base_name'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'rebuilds'}; {'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'build_first'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'build_first'}, {'id': '207', 'type': 'keyword_argument', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'cache_from'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'cache_from'}; {'id': '210', 'type': 'keyword_argument', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'buildargs'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'buildargs'}, {'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'squash'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'squash'}; {'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'secret_files'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'secret_files'}, {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'base_image'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'buildname'}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'build_first'}; {'id': '226', 'type': 'None', 'children': []}, {'id': '227', 'type': 'for_statement', 'children': ['228', '231', '245']}; {'id': '228', 'type': 'pattern_list', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'sourceimage'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'call', 'children': ['235', '242']}, {'id': '235', 'type': 'attribute', 'children': ['236', '241']}; {'id': '236', 'type': 'subscript', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'ymldefs'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'base_name'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '242', 'type': 'argument_list', 'children': ['243', '244']}, {'id': '243', 'type': 'string', 'children': [], 'value': "'copy_from'"}; {'id': '244', 'type': 'dictionary', 'children': []}, {'id': '245', 'type': 'block', 'children': ['246', '253']}; {'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': 'sourceimages'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'sourceimage'}, {'id': '253', 'type': 'for_statement', 'children': ['254', '257', '261']}; {'id': '254', 'type': 'pattern_list', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'sourcepath'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'destpath'}, {'id': '257', 'type': 'call', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'iteritems'}, {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '261', 'type': 'block', 'children': ['262', '266', '274', '309']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'augmented_assignment', 'children': ['264', '265'], 'value': '+='}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'istep'}, {'id': '265', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'buildname'}, {'id': '269', 'type': 'binary_operator', 'children': ['270', '271'], 'value': '%'}; {'id': '270', 'type': 'string', 'children': [], 'value': "'dmkbuild_%s_%d'"}, {'id': '271', 'type': 'tuple', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'image'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'istep'}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'build_steps'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'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': 'dockermake'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'step'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'FileCopyStep'}; {'id': '286', 'type': 'argument_list', 'children': ['287', '288', '289', '290', '291', '292', '297', '298', '303', '306']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'sourceimage'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'sourcepath'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'destpath'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'base_name'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'base_image'}; {'id': '292', 'type': 'subscript', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'ymldefs'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'base_name'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'buildname'}; {'id': '298', 'type': 'keyword_argument', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'bust_cache'}; {'id': '300', 'type': 'comparison_operator', 'children': ['301', '302'], 'value': 'in'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'base_name'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'rebuilds'}, {'id': '303', 'type': 'keyword_argument', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'build_first'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'build_first'}; {'id': '306', 'type': 'keyword_argument', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'cache_from'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'cache_from'}, {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'assignment', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'base_image'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'buildname'}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'assignment', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'sourcebuilds'}; {'id': '316', 'type': 'list_comprehension', 'children': ['317', '332']}, {'id': '317', 'type': 'call', 'children': ['318', '321']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'generate_build'}, {'id': '321', 'type': 'argument_list', 'children': ['322', '323', '324', '327', '330']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'img'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '324', 'type': 'keyword_argument', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'cache_repo'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'cache_repo'}, {'id': '327', 'type': 'keyword_argument', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'cache_tag'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'cache_tag'}; {'id': '330', 'type': 'dictionary_splat', 'children': ['331']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '332', 'type': 'for_in_clause', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'img'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'sourceimages'}, {'id': '335', 'type': 'return_statement', 'children': ['336']}; {'id': '336', 'type': 'call', 'children': ['337', '340']}, {'id': '337', 'type': 'attribute', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'builds'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'BuildTarget'}; {'id': '340', 'type': 'argument_list', 'children': ['341', '344', '347', '350', '353', '356']}, {'id': '341', 'type': 'keyword_argument', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'imagename'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '344', 'type': 'keyword_argument', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'targetname'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'targetname'}, {'id': '347', 'type': 'keyword_argument', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'steps'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'build_steps'}; {'id': '350', 'type': 'keyword_argument', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'sourcebuilds'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'sourcebuilds'}, {'id': '353', 'type': 'keyword_argument', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'from_image'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'from_image'}; {'id': '356', 'type': 'dictionary_splat', 'children': ['357']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'kwargs'} | def generate_build(self, image, targetname, rebuilds=None, cache_repo='', cache_tag='',
buildargs=None, **kwargs):
from_image = self.get_external_base_image(image)
if cache_repo or cache_tag:
cache_from = utils.generate_name(image, cache_repo, cache_tag)
else:
cache_from = None
if from_image is None:
raise errors.NoBaseError("No base image found in %s's dependencies" % image)
if isinstance(from_image, ExternalDockerfile):
build_first = from_image
base_image = from_image.tag
else:
base_image = from_image
build_first = None
build_steps = []
istep = 0
sourceimages = set()
if rebuilds is None:
rebuilds = []
else:
rebuilds = set(rebuilds)
for base_name in self.sort_dependencies(image):
istep += 1
buildname = 'dmkbuild_%s_%d' % (image, istep)
secret_files = self.ymldefs[base_name].get('secret_files', None)
squash = self.ymldefs[base_name].get('squash', bool(secret_files))
build_steps.append(
dockermake.step.BuildStep(
base_name,
base_image,
self.ymldefs[base_name],
buildname,
bust_cache=base_name in rebuilds,
build_first=build_first, cache_from=cache_from,
buildargs=buildargs,
squash=squash,
secret_files=secret_files))
base_image = buildname
build_first = None
for sourceimage, files in iteritems(self.ymldefs[base_name].get('copy_from', {})):
sourceimages.add(sourceimage)
for sourcepath, destpath in iteritems(files):
istep += 1
buildname = 'dmkbuild_%s_%d' % (image, istep)
build_steps.append(
dockermake.step.FileCopyStep(
sourceimage, sourcepath, destpath,
base_name, base_image, self.ymldefs[base_name],
buildname, bust_cache=base_name in rebuilds,
build_first=build_first, cache_from=cache_from))
base_image = buildname
sourcebuilds = [self.generate_build(img,
img,
cache_repo=cache_repo,
cache_tag=cache_tag,
**kwargs)
for img in sourceimages]
return builds.BuildTarget(imagename=image,
targetname=targetname,
steps=build_steps,
sourcebuilds=sourcebuilds,
from_image=from_image,
**kwargs) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_dependencies'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'dependencies'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '21', '27', '41', '53', '59']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dependencies'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'dependencies'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'if_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'in'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'dependencies'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'return_statement', 'children': []}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'requires'}; {'id': '30', 'type': 'call', 'children': ['31', '38']}, {'id': '31', 'type': 'attribute', 'children': ['32', '37']}; {'id': '32', 'type': 'subscript', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ymldefs'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'image'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}, {'id': '39', 'type': 'string', 'children': [], 'value': "'requires'"}; {'id': '40', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '41', 'type': 'for_statement', 'children': ['42', '43', '44']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'dep'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'requires'}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sort_dependencies'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'dependencies'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '58']}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'dependencies'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '58', 'type': 'None', 'children': []}, {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'dependencies'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'keys'} | def sort_dependencies(self, image, dependencies=None):
if dependencies is None:
dependencies = OrderedDict()
if image in dependencies:
return
requires = self.ymldefs[image].get('requires', [])
for dep in requires:
self.sort_dependencies(dep, dependencies)
dependencies[image] = None
return dependencies.keys() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_external_base_image'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '21', '29', '55', '62', '82', '136', '146', '163', '224', '232']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'stack'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'stack'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'mydef'}; {'id': '24', 'type': 'subscript', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ymldefs'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'image'}, {'id': '29', 'type': 'if_statement', 'children': ['30', '33']}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'in'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'stack'}, {'id': '33', 'type': 'block', 'children': ['34', '41']}; {'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': 'stack'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'image'}, {'id': '41', 'type': 'raise_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'CircularDependencyError'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '+'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'Circular dependency found:\\n'"}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'string', 'children': [], 'value': "'->'"}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'stack'}, {'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': 'stack'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '62', 'type': 'if_statement', 'children': ['63', '70']}, {'id': '63', 'type': 'boolean_operator', 'children': ['64', '67'], 'value': 'and'}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'in'}, {'id': '65', 'type': 'string', 'children': [], 'value': "'FROM'"}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'mydef'}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'in'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'FROM_DOCKERFILE'"}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'mydef'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'raise_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'MultipleBaseError'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '81'], 'value': '+'}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '%'}, {'id': '79', 'type': 'string', 'children': [], 'value': '\'ERROR: Image "%s" has both a "FROM" and a "FROM_DOCKERFILE" field.\''}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'image'}, {'id': '81', 'type': 'string', 'children': [], 'value': "' It should have at most ONE of these fields.'"}; {'id': '82', 'type': 'if_statement', 'children': ['83', '86', '93', '130']}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'in'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'FROM'"}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'mydef'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'externalbase'}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'mydef'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'FROM'"}, {'id': '93', 'type': 'elif_clause', 'children': ['94', '97']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'in'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'FROM_DOCKERFILE'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'mydef'}, {'id': '97', 'type': 'block', 'children': ['98', '104', '122']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'mydef'}, {'id': '103', 'type': 'string', 'children': [], 'value': "'FROM_DOCKERFILE'"}; {'id': '104', 'type': 'if_statement', 'children': ['105', '110']}, {'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'not'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': '_external_dockerfiles'}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '118']}, {'id': '113', 'type': 'subscript', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': '_external_dockerfiles'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'ExternalDockerfile'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'externalbase'}, {'id': '125', 'type': 'subscript', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': '_external_dockerfiles'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '130', 'type': 'else_clause', 'children': ['131']}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'externalbase'}, {'id': '135', 'type': 'None', 'children': []}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'requires'}, {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'mydef'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'string', 'children': [], 'value': "'requires'"}, {'id': '145', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '146', 'type': 'if_statement', 'children': ['147', '153']}, {'id': '147', 'type': 'not_operator', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'requires'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'raise_statement', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'InvalidRequiresList'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '%'}, {'id': '161', 'type': 'string', 'children': [], 'value': '\'Requirements for image "%s" are not a list\''}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'image'}, {'id': '163', 'type': 'for_statement', 'children': ['164', '165', '166']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'requires'}; {'id': '166', 'type': 'block', 'children': ['167', '183']}, {'id': '167', 'type': 'try_statement', 'children': ['168', '179']}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'otherexternal'}; {'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': 'get_external_base_image'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'base'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'stack'}, {'id': '179', 'type': 'except_clause', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'continue_statement', 'children': []}, {'id': '183', 'type': 'if_statement', 'children': ['184', '187', '192', '198']}; {'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': 'is'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'externalbase'}; {'id': '186', 'type': 'None', 'children': []}, {'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': 'externalbase'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'otherexternal'}; {'id': '192', 'type': 'elif_clause', 'children': ['193', '196']}, {'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': 'is'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'otherexternal'}, {'id': '195', 'type': 'None', 'children': []}; {'id': '196', 'type': 'block', 'children': ['197']}, {'id': '197', 'type': 'continue_statement', 'children': []}; {'id': '198', 'type': 'elif_clause', 'children': ['199', '202']}, {'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': '!='}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'externalbase'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'otherexternal'}; {'id': '202', 'type': 'block', 'children': ['203']}, {'id': '203', 'type': 'raise_statement', 'children': ['204']}; {'id': '204', 'type': 'call', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'ConflictingBaseError'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'binary_operator', 'children': ['210', '219'], 'value': '+'}; {'id': '210', 'type': 'binary_operator', 'children': ['211', '214'], 'value': '+'}, {'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '%'}; {'id': '212', 'type': 'string', 'children': [], 'value': '\'Multiple external dependencies: definition "%s" depends on:\\n\''}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '214', 'type': 'binary_operator', 'children': ['215', '216'], 'value': '%'}, {'id': '215', 'type': 'string', 'children': [], 'value': "' %s (FROM: %s), and\\n'"}; {'id': '216', 'type': 'tuple', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'externalbase'}, {'id': '219', 'type': 'binary_operator', 'children': ['220', '221'], 'value': '%'}; {'id': '220', 'type': 'string', 'children': [], 'value': "' %s (FROM: %s).'"}, {'id': '221', 'type': 'tuple', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'base'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'otherexternal'}; {'id': '224', 'type': 'assert_statement', 'children': ['225']}, {'id': '225', 'type': 'comparison_operator', 'children': ['226', '231'], 'value': '=='}; {'id': '226', 'type': 'call', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'stack'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '230', 'type': 'argument_list', 'children': []}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '232', 'type': 'return_statement', 'children': ['233']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'externalbase'} | def get_external_base_image(self, image, stack=None):
if stack is None:
stack = list()
mydef = self.ymldefs[image]
if image in stack:
stack.append(image)
raise errors.CircularDependencyError('Circular dependency found:\n' + '->'.join(stack))
stack.append(image)
if 'FROM' in mydef and 'FROM_DOCKERFILE' in mydef:
raise errors.MultipleBaseError(
'ERROR: Image "%s" has both a "FROM" and a "FROM_DOCKERFILE" field.' % image +
' It should have at most ONE of these fields.')
if 'FROM' in mydef:
externalbase = mydef['FROM']
elif 'FROM_DOCKERFILE' in mydef:
path = mydef['FROM_DOCKERFILE']
if path not in self._external_dockerfiles:
self._external_dockerfiles[path] = ExternalDockerfile(path)
externalbase = self._external_dockerfiles[path]
else:
externalbase = None
requires = mydef.get('requires', [])
if not isinstance(requires, list):
raise errors.InvalidRequiresList('Requirements for image "%s" are not a list' % image)
for base in requires:
try:
otherexternal = self.get_external_base_image(base, stack)
except ValueError:
continue
if externalbase is None:
externalbase = otherexternal
elif otherexternal is None:
continue
elif externalbase != otherexternal:
raise errors.ConflictingBaseError(
'Multiple external dependencies: definition "%s" depends on:\n' % image +
' %s (FROM: %s), and\n' % (image, externalbase) +
' %s (FROM: %s).' % (base, otherexternal))
assert stack.pop() == image
return externalbase |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_htmlRenderDict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'pathParts'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'statDict'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '7', 'type': 'block', 'children': ['8', '19', '25', '29', '36', '173', '187']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '11', 'type': 'call', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'statDict'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '18', 'type': 'argument_list', 'children': []}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'links'}; {'id': '28', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'string', 'children': [], 'value': '\'<div class="level">\''}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '39']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '39', 'type': 'block', 'children': ['40', '52', '58', '71']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'keyStr'}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'cgi'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'escape'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_utf8str'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'statDict'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '58', 'type': 'if_statement', 'children': ['59', '64']}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'__call__'"}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '70', 'type': 'argument_list', 'children': []}, {'id': '71', 'type': 'if_statement', 'children': ['72', '77', '140']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '76', 'type': 'string', 'children': [], 'value': "'keys'"}, {'id': '77', 'type': 'block', 'children': ['78', '85']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'valuePath'}, {'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '+'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'pathParts'}, {'id': '83', 'type': 'tuple', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'keyStr'}, {'id': '85', 'type': 'if_statement', 'children': ['86', '99', '122']}; {'id': '86', 'type': 'boolean_operator', 'children': ['87', '94'], 'value': 'and'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '89', 'type': 'argument_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'scales'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'StatContainer'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'isCollapsed'}; {'id': '98', 'type': 'argument_list', 'children': []}, {'id': '99', 'type': 'block', 'children': ['100', '111']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '+'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'/status/'"}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'valuePath'}, {'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': 'links'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '%'}; {'id': '118', 'type': 'string', 'children': [], 'value': '\'<div class="key"><a href="%s">%s</a></div>\''}, {'id': '119', 'type': 'tuple', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'keyStr'}; {'id': '122', 'type': 'else_clause', 'children': ['123']}, {'id': '123', 'type': 'block', 'children': ['124', '133']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '%'}, {'id': '131', 'type': 'string', 'children': [], 'value': '\'<div class="key">%s</div>\''}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'keyStr'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': '_htmlRenderDict'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '138', '139']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'valuePath'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '140', 'type': 'else_clause', 'children': ['141']}, {'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': 'output'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'binary_operator', 'children': ['149', '150'], 'value': '%'}, {'id': '149', 'type': 'string', 'children': [], 'value': '\'<div><span class="key">%s</span> <span class="%s">%s</span></div>\''}; {'id': '150', 'type': 'tuple', 'children': ['151', '152', '158']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'keyStr'}; {'id': '152', 'type': 'attribute', 'children': ['153', '157']}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '158', 'type': 'call', 'children': ['159', '170']}, {'id': '159', 'type': 'attribute', 'children': ['160', '169']}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'cgi'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'escape'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': '_utf8str'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '172']}, {'id': '171', 'type': 'string', 'children': [], 'value': "'\\n'"}; {'id': '172', 'type': 'string', 'children': [], 'value': "'<br/>'"}, {'id': '173', 'type': 'if_statement', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'links'}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'for_statement', 'children': ['177', '178', '179']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'links'}, {'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': 'output'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'link'}, {'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': 'output'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}, {'id': '193', 'type': 'string', 'children': [], 'value': "'</div>'"} | def _htmlRenderDict(pathParts, statDict, output):
keys = list(statDict.keys())
keys.sort()
links = []
output.write('<div class="level">')
for key in keys:
keyStr = cgi.escape(_utf8str(key))
value = statDict[key]
if hasattr(value, '__call__'):
value = value()
if hasattr(value, 'keys'):
valuePath = pathParts + (keyStr,)
if isinstance(value, scales.StatContainer) and value.isCollapsed():
link = '/status/' + '/'.join(valuePath)
links.append('<div class="key"><a href="%s">%s</a></div>' % (link, keyStr))
else:
output.write('<div class="key">%s</div>' % keyStr)
_htmlRenderDict(valuePath, value, output)
else:
output.write('<div><span class="key">%s</span> <span class="%s">%s</span></div>' %
(keyStr, type(value).__name__, cgi.escape(_utf8str(value)).replace('\n', '<br/>')))
if links:
for link in links:
output.write(link)
output.write('</div>') |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '96', '98']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_session'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '14', '23', '32', '41', '46', '51', '56', '61', '66', '75', '80', '85']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kind'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'SessionKind'}, {'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'proxy_user'}, {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'typed_default_parameter', 'children': ['15', '16', '22']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'jars'}; {'id': '16', 'type': 'type', 'children': ['17']}, {'id': '17', 'type': 'generic_type', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'List'}, {'id': '19', 'type': 'type_parameter', 'children': ['20']}; {'id': '20', 'type': 'type', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'typed_default_parameter', 'children': ['24', '25', '31']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'py_files'}, {'id': '25', 'type': 'type', 'children': ['26']}; {'id': '26', 'type': 'generic_type', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'List'}; {'id': '28', 'type': 'type_parameter', 'children': ['29']}, {'id': '29', 'type': 'type', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'typed_default_parameter', 'children': ['33', '34', '40']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'files'}; {'id': '34', 'type': 'type', 'children': ['35']}, {'id': '35', 'type': 'generic_type', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'List'}, {'id': '37', 'type': 'type_parameter', 'children': ['38']}; {'id': '38', 'type': 'type', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '40', 'type': 'None', 'children': []}, {'id': '41', 'type': 'typed_default_parameter', 'children': ['42', '43', '45']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'driver_memory'}, {'id': '43', 'type': 'type', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '45', 'type': 'None', 'children': []}; {'id': '46', 'type': 'typed_default_parameter', 'children': ['47', '48', '50']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'driver_cores'}; {'id': '48', 'type': 'type', 'children': ['49']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '50', 'type': 'None', 'children': []}, {'id': '51', 'type': 'typed_default_parameter', 'children': ['52', '53', '55']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'executor_memory'}, {'id': '53', 'type': 'type', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'typed_default_parameter', 'children': ['57', '58', '60']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'executor_cores'}; {'id': '58', 'type': 'type', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '60', 'type': 'None', 'children': []}, {'id': '61', 'type': 'typed_default_parameter', 'children': ['62', '63', '65']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'num_executors'}, {'id': '63', 'type': 'type', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'typed_default_parameter', 'children': ['67', '68', '74']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'archives'}; {'id': '68', 'type': 'type', 'children': ['69']}, {'id': '69', 'type': 'generic_type', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'List'}, {'id': '71', 'type': 'type_parameter', 'children': ['72']}; {'id': '72', 'type': 'type', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '74', 'type': 'None', 'children': []}, {'id': '75', 'type': 'typed_default_parameter', 'children': ['76', '77', '79']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'queue'}, {'id': '77', 'type': 'type', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '79', 'type': 'None', 'children': []}; {'id': '80', 'type': 'typed_default_parameter', 'children': ['81', '82', '84']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '82', 'type': 'type', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '84', 'type': 'None', 'children': []}, {'id': '85', 'type': 'typed_default_parameter', 'children': ['86', '87', '95']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'spark_conf'}, {'id': '87', 'type': 'type', 'children': ['88']}; {'id': '88', 'type': 'generic_type', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'Dict'}; {'id': '90', 'type': 'type_parameter', 'children': ['91', '93']}, {'id': '91', 'type': 'type', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '93', 'type': 'type', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'Any'}, {'id': '95', 'type': 'None', 'children': []}; {'id': '96', 'type': 'type', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'Session'}; {'id': '98', 'type': 'block', 'children': ['99', '116', '128', '137', '148', '159', '170', '181', '192', '203', '214', '225', '236', '247', '258', '269', '280', '294']}, {'id': '99', 'type': 'if_statement', 'children': ['100', '105', '110']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'legacy_server'}; {'id': '104', 'type': 'argument_list', 'children': []}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'valid_kinds'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'VALID_LEGACY_SESSION_KINDS'}; {'id': '110', 'type': 'else_clause', 'children': ['111']}, {'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': 'valid_kinds'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'VALID_SESSION_KINDS'}; {'id': '116', 'type': 'if_statement', 'children': ['117', '120']}, {'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': 'not'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'kind'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'valid_kinds'}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'raise_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'concatenated_string', 'children': ['126', '127']}; {'id': '126', 'type': 'string', 'children': [], 'value': 'f"{kind} is not a valid session kind for a Livy server of "'}, {'id': '127', 'type': 'string', 'children': [], 'value': 'f"this version (should be one of {valid_kinds})"'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'body'}, {'id': '131', 'type': 'dictionary', 'children': ['132']}; {'id': '132', 'type': 'pair', 'children': ['133', '134']}, {'id': '133', 'type': 'string', 'children': [], 'value': '"kind"'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '137', 'type': 'if_statement', 'children': ['138', '141']}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': 'is'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'proxy_user'}; {'id': '140', 'type': 'None', 'children': []}, {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '147']}; {'id': '144', 'type': 'subscript', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '146', 'type': 'string', 'children': [], 'value': '"proxyUser"'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'proxy_user'}; {'id': '148', 'type': 'if_statement', 'children': ['149', '152']}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': 'is'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'jars'}, {'id': '151', 'type': 'None', 'children': []}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '158']}, {'id': '155', 'type': 'subscript', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'body'}, {'id': '157', 'type': 'string', 'children': [], 'value': '"jars"'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'jars'}, {'id': '159', 'type': 'if_statement', 'children': ['160', '163']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': 'is'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'py_files'}; {'id': '162', 'type': 'None', 'children': []}, {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '169']}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '168', 'type': 'string', 'children': [], 'value': '"pyFiles"'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'py_files'}; {'id': '170', 'type': 'if_statement', 'children': ['171', '174']}, {'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': 'is'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '173', 'type': 'None', 'children': []}; {'id': '174', 'type': 'block', 'children': ['175']}, {'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': 'body'}, {'id': '179', 'type': 'string', 'children': [], 'value': '"files"'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'files'}, {'id': '181', 'type': 'if_statement', 'children': ['182', '185']}; {'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': 'is'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'driver_memory'}; {'id': '184', 'type': 'None', 'children': []}, {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '191']}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '190', 'type': 'string', 'children': [], 'value': '"driverMemory"'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'driver_memory'}; {'id': '192', 'type': 'if_statement', 'children': ['193', '196']}, {'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': 'is'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'driver_cores'}, {'id': '195', 'type': 'None', 'children': []}; {'id': '196', 'type': 'block', 'children': ['197']}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '202']}, {'id': '199', 'type': 'subscript', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'body'}, {'id': '201', 'type': 'string', 'children': [], 'value': '"driverCores"'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'driver_cores'}, {'id': '203', 'type': 'if_statement', 'children': ['204', '207']}; {'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': 'is'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'executor_memory'}; {'id': '206', 'type': 'None', 'children': []}, {'id': '207', 'type': 'block', 'children': ['208']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '213']}; {'id': '210', 'type': 'subscript', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '212', 'type': 'string', 'children': [], 'value': '"executorMemory"'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'executor_memory'}; {'id': '214', 'type': 'if_statement', 'children': ['215', '218']}, {'id': '215', 'type': 'comparison_operator', 'children': ['216', '217'], 'value': 'is'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'executor_cores'}, {'id': '217', 'type': 'None', 'children': []}; {'id': '218', 'type': 'block', 'children': ['219']}, {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '224']}, {'id': '221', 'type': 'subscript', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'body'}, {'id': '223', 'type': 'string', 'children': [], 'value': '"executorCores"'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'executor_cores'}, {'id': '225', 'type': 'if_statement', 'children': ['226', '229']}; {'id': '226', 'type': 'comparison_operator', 'children': ['227', '228'], 'value': 'is'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'num_executors'}; {'id': '228', 'type': 'None', 'children': []}, {'id': '229', 'type': 'block', 'children': ['230']}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'assignment', 'children': ['232', '235']}; {'id': '232', 'type': 'subscript', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '234', 'type': 'string', 'children': [], 'value': '"numExecutors"'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'num_executors'}; {'id': '236', 'type': 'if_statement', 'children': ['237', '240']}, {'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': 'is'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'archives'}, {'id': '239', 'type': 'None', 'children': []}; {'id': '240', 'type': 'block', 'children': ['241']}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '246']}, {'id': '243', 'type': 'subscript', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'body'}, {'id': '245', 'type': 'string', 'children': [], 'value': '"archives"'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'archives'}, {'id': '247', 'type': 'if_statement', 'children': ['248', '251']}; {'id': '248', 'type': 'comparison_operator', 'children': ['249', '250'], 'value': 'is'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '250', 'type': 'None', 'children': []}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'assignment', 'children': ['254', '257']}; {'id': '254', 'type': 'subscript', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '256', 'type': 'string', 'children': [], 'value': '"queue"'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '258', 'type': 'if_statement', 'children': ['259', '262']}, {'id': '259', 'type': 'comparison_operator', 'children': ['260', '261'], 'value': 'is'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '261', 'type': 'None', 'children': []}; {'id': '262', 'type': 'block', 'children': ['263']}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '268']}, {'id': '265', 'type': 'subscript', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'body'}, {'id': '267', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '269', 'type': 'if_statement', 'children': ['270', '273']}; {'id': '270', 'type': 'comparison_operator', 'children': ['271', '272'], 'value': 'is'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'spark_conf'}; {'id': '272', 'type': 'None', 'children': []}, {'id': '273', 'type': 'block', 'children': ['274']}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'assignment', 'children': ['276', '279']}; {'id': '276', 'type': 'subscript', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '278', 'type': 'string', 'children': [], 'value': '"conf"'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'spark_conf'}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '283', 'type': 'call', 'children': ['284', '289']}; {'id': '284', 'type': 'attribute', 'children': ['285', '288']}, {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'post'}, {'id': '289', 'type': 'argument_list', 'children': ['290', '291']}; {'id': '290', 'type': 'string', 'children': [], 'value': '"/sessions"'}, {'id': '291', 'type': 'keyword_argument', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '294', 'type': 'return_statement', 'children': ['295']}, {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'Session'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'from_json'}, {'id': '299', 'type': 'argument_list', 'children': ['300']} | def create_session(
self,
kind: SessionKind,
proxy_user: str = None,
jars: List[str] = None,
py_files: List[str] = None,
files: List[str] = None,
driver_memory: str = None,
driver_cores: int = None,
executor_memory: str = None,
executor_cores: int = None,
num_executors: int = None,
archives: List[str] = None,
queue: str = None,
name: str = None,
spark_conf: Dict[str, Any] = None,
) -> Session:
if self.legacy_server():
valid_kinds = VALID_LEGACY_SESSION_KINDS
else:
valid_kinds = VALID_SESSION_KINDS
if kind not in valid_kinds:
raise ValueError(
f"{kind} is not a valid session kind for a Livy server of "
f"this version (should be one of {valid_kinds})"
)
body = {"kind": kind.value}
if proxy_user is not None:
body["proxyUser"] = proxy_user
if jars is not None:
body["jars"] = jars
if py_files is not None:
body["pyFiles"] = py_files
if files is not None:
body["files"] = files
if driver_memory is not None:
body["driverMemory"] = driver_memory
if driver_cores is not None:
body["driverCores"] = driver_cores
if executor_memory is not None:
body["executorMemory"] = executor_memory
if executor_cores is not None:
body["executorCores"] = executor_cores
if num_executors is not None:
body["numExecutors"] = num_executors
if archives is not None:
body["archives"] = archives
if queue is not None:
body["queue"] = queue
if name is not None:
body["name"] = name
if spark_conf is not None:
body["conf"] = spark_conf
data = self._client.post("/sessions", data=body)
return Session.from_json(data) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sine_psd'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'number_of_tapers'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'number_of_iterations'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'degree_of_smoothing'}; {'id': '14', 'type': 'float', 'children': [], 'value': '1.0'}, {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'statistics'}, {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '20', 'type': 'False', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '47', '56', '63', '83', '90', '101', '110', '119', '179', '277', '283', '297']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '26', '41']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '25', 'type': 'True', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'byref'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'c_char'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'y'"}, {'id': '41', 'type': 'else_clause', 'children': ['42']}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '46', 'type': 'None', 'children': []}, {'id': '47', 'type': 'if_statement', 'children': ['48', '51']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'number_of_tapers'}; {'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': 'number_of_tapers'}, {'id': '55', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_MtspecType'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': '"float32"'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'data'}; {'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': 'require'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72', '77']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'requirements'}, {'id': '79', 'type': 'list', 'children': ['80'], 'value': '[mt.order]'}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'npts'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'number_of_frequency_bins'}, {'id': '93', 'type': 'binary_operator', 'children': ['94', '100'], 'value': '+'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '/'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'npts'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'frequency_bins'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'number_of_frequency_bins'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'spectrum'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'number_of_frequency_bins'}, {'id': '119', 'type': 'if_statement', 'children': ['120', '123', '171']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': 'is'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'statistics'}; {'id': '122', 'type': 'True', 'children': []}, {'id': '123', 'type': 'block', 'children': ['124', '141', '160']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'tapers_per_freq_point'}, {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '131', 'type': 'argument_list', 'children': ['132', '133', '136']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'number_of_frequency_bins'}, {'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'dtype'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'int32'"}; {'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144', '145']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'tapers_per_freq_point_p'}; {'id': '144', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '145', 'type': 'call', 'children': ['146', '151']}; {'id': '146', 'type': 'attribute', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'tapers_per_freq_point'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'ctypes'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'data_as'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'POINTER'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'c_int'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'tuple', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'number_of_frequency_bins'}; {'id': '170', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '171', 'type': 'else_clause', 'children': ['172']}; {'id': '172', 'type': 'block', 'children': ['173']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'tapers_per_freq_point_p'}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '178', 'type': 'None', 'children': []}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'mtspeclib'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'sine_psd_'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '196', '207', '213', '224', '235', '246', '257', '263', '269', '270', '276']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'byref'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'c_int'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'npts'}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'byref'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'c_float'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'delta'}, {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'byref'}, {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'c_int'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'number_of_tapers'}; {'id': '224', 'type': 'call', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'byref'}; {'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': 'C'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'c_int'}, {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'number_of_iterations'}, {'id': '235', 'type': 'call', 'children': ['236', '239']}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'byref'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'c_float'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'degree_of_smoothing'}; {'id': '246', 'type': 'call', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'byref'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}, {'id': '251', 'type': 'call', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'c_int'}, {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'number_of_frequency_bins'}, {'id': '257', 'type': 'call', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'frequency_bins'}, {'id': '263', 'type': 'call', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'spectrum'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'tapers_per_freq_point_p'}; {'id': '270', 'type': 'call', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'assignment', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'return_values'}; {'id': '280', 'type': 'list', 'children': ['281', '282'], 'value': '[spectrum, frequency_bins]'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'spectrum'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'frequency_bins'}, {'id': '283', 'type': 'if_statement', 'children': ['284', '287']}; {'id': '284', 'type': 'comparison_operator', 'children': ['285', '286'], 'value': 'is'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'statistics'}; {'id': '286', 'type': 'True', 'children': []}, {'id': '287', 'type': 'block', 'children': ['288']}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}, {'id': '289', 'type': 'call', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'return_values'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'list', 'children': ['295', '296'], 'value': '[errors, tapers_per_freq_point]'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'tapers_per_freq_point'}, {'id': '297', 'type': 'return_statement', 'children': ['298']} | def sine_psd(data, delta, number_of_tapers=None, number_of_iterations=2,
degree_of_smoothing=1.0, statistics=False, verbose=False):
if verbose is True:
verbose = C.byref(C.c_char('y'))
else:
verbose = None
if number_of_tapers is None:
number_of_tapers = 0
mt = _MtspecType("float32")
data = np.require(data, dtype=mt.float, requirements=[mt.order])
npts = len(data)
number_of_frequency_bins = int(npts / 2) + 1
frequency_bins = mt.empty(number_of_frequency_bins)
spectrum = mt.empty(number_of_frequency_bins)
if statistics is True:
tapers_per_freq_point = np.empty(number_of_frequency_bins,
dtype='int32', order=mt.order)
tapers_per_freq_point_p = \
tapers_per_freq_point.ctypes.data_as(C.POINTER(C.c_int))
errors = mt.empty((number_of_frequency_bins, 2))
else:
tapers_per_freq_point_p = errors = None
mtspeclib.sine_psd_(
C.byref(C.c_int(npts)),
C.byref(C.c_float(delta)), mt.p(data),
C.byref(C.c_int(number_of_tapers)),
C.byref(C.c_int(number_of_iterations)),
C.byref(C.c_float(degree_of_smoothing)),
C.byref(C.c_int(number_of_frequency_bins)),
mt.p(frequency_bins), mt.p(spectrum),
tapers_per_freq_point_p, mt.p(errors), verbose)
return_values = [spectrum, frequency_bins]
if statistics is True:
return_values.extend([errors, tapers_per_freq_point])
return return_values |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'mt_deconvolve'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data_a'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data_b'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'delta'}, {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'nfft'}, {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'time_bandwidth'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'number_of_tapers'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '18', 'type': 'string', 'children': [], 'value': '"adaptive"'}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'demean'}, {'id': '21', 'type': 'True', 'children': []}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'fmax'}; {'id': '24', 'type': 'float', 'children': [], 'value': '0.0'}, {'id': '25', 'type': 'block', 'children': ['26', '33', '46', '67', '74', '90', '108', '126', '134', '147', '172', '181', '190', '199', '208', '217', '382']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'npts'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'data_a'}, {'id': '33', 'type': 'if_statement', 'children': ['34', '40']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '39'], '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': 'identifier', 'children': [], 'value': 'data_b'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'npts'}; {'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': '"Input arrays must have the same length!"'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50', '55']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'nfft'}, {'id': '49', 'type': 'None', 'children': []}; {'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': 'nfft'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'npts'}, {'id': '55', 'type': 'elif_clause', 'children': ['56', '59']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '<'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'nfft'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'npts'}, {'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': 'concatenated_string', 'children': ['65', '66']}, {'id': '65', 'type': 'string', 'children': [], 'value': '"nfft must be larger then the number of samples in "'}; {'id': '66', 'type': 'string', 'children': [], 'value': '"the array."'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': '_MtspecType'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'string', 'children': [], 'value': '"float32"'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'number_of_tapers'}, {'id': '77', 'type': 'None', 'children': []}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'number_of_tapers'}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '89'], 'value': '-'}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '*'}, {'id': '87', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'time_bandwidth'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'data_a'}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'require'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99', '102']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'data_a'}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'requirements'}; {'id': '104', 'type': 'list', 'children': ['105'], 'value': '[mt.order]'}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'data_b'}, {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'require'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '117', '120']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'data_b'}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'requirements'}; {'id': '122', 'type': 'list', 'children': ['123'], 'value': '[mt.order]'}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'nf'}, {'id': '129', 'type': 'binary_operator', 'children': ['130', '133'], 'value': '+'}; {'id': '130', 'type': 'binary_operator', 'children': ['131', '132'], 'value': '//'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'nfft'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '134', 'type': 'if_statement', 'children': ['135', '136', '141']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'demean'}; {'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': 'demean'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '1'}, {'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': 'demean'}; {'id': '146', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '147', 'type': 'if_statement', 'children': ['148', '151', '156', '165']}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': '=='}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'weights'}; {'id': '150', 'type': 'string', 'children': [], 'value': '"constant"'}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'adaptive'}, {'id': '155', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '156', 'type': 'elif_clause', 'children': ['157', '160']}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': '=='}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'weights'}, {'id': '159', 'type': 'string', 'children': [], 'value': '"adaptive"'}; {'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': 'adaptive'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '0'}, {'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': 'ValueError'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'string', 'children': [], 'value': '\'Weights must be either "adaptive" or "constant".\''}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'tfun'}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'nfft'}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '184', 'type': 'call', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'nf'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'spec_ratio'}, {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'nf'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'speci'}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'nf'}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'specj'}, {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'empty'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'nf'}, {'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': 'mtspeclib'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'mt_deconv_'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '237', '251', '265', '271', '277', '291', '305', '319', '330', '336', '342', '348', '354', '360', '371']}, {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'byref'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'c_int'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'npts'}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'byref'}, {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '246']}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'c_int'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'nfft'}, {'id': '251', 'type': 'call', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'byref'}, {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'c_float'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'call', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'delta'}, {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'data_a'}, {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'mt'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'p'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'data_b'}, {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'byref'}, {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'call', 'children': ['283', '286']}, {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'c_float'}; {'id': '286', 'type': 'argument_list', 'children': ['287']}, {'id': '287', 'type': 'call', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '289', 'type': 'argument_list', 'children': ['290']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'time_bandwidth'}, {'id': '291', 'type': 'call', 'children': ['292', '295']}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'byref'}, {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'call', 'children': ['297', '300']}, {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'c_int'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}, {'id': '301', 'type': 'call', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '303', 'type': 'argument_list', 'children': ['304']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'number_of_tapers'}, {'id': '305', 'type': 'call', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'byref'}, {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'call', 'children': ['311', '314']}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'c_int'}; {'id': '314', 'type': 'argument_list', 'children': ['315']}, {'id': '315', 'type': 'call', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '317', 'type': 'argument_list', 'children': ['318']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'nf'}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'byref'}, {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'call', 'children': ['325', '328']}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'c_int'}; {'id': '328', 'type': 'argument_list', 'children': ['329']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'adaptive'}; {'id': '330', 'type': 'call', 'children': ['331', '334']}, {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '334', 'type': 'argument_list', 'children': ['335']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'freq'}; {'id': '336', 'type': 'call', 'children': ['337', '340']}, {'id': '337', 'type': 'attribute', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '340', 'type': 'argument_list', 'children': ['341']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'tfun'}; {'id': '342', 'type': 'call', 'children': ['343', '346']}, {'id': '343', 'type': 'attribute', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '346', 'type': 'argument_list', 'children': ['347']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'spec_ratio'}; {'id': '348', 'type': 'call', 'children': ['349', '352']}, {'id': '349', 'type': 'attribute', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '352', 'type': 'argument_list', 'children': ['353']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'speci'}; {'id': '354', 'type': 'call', 'children': ['355', '358']}, {'id': '355', 'type': 'attribute', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'mt'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '358', 'type': 'argument_list', 'children': ['359']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'specj'}; {'id': '360', 'type': 'call', 'children': ['361', '364']}, {'id': '361', 'type': 'attribute', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'byref'}; {'id': '364', 'type': 'argument_list', 'children': ['365']}, {'id': '365', 'type': 'call', 'children': ['366', '369']}; {'id': '366', 'type': 'attribute', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'c_int'}, {'id': '369', 'type': 'argument_list', 'children': ['370']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'demean'}, {'id': '371', 'type': 'call', 'children': ['372', '375']}; {'id': '372', 'type': 'attribute', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'C'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'byref'}, {'id': '375', 'type': 'argument_list', 'children': ['376']}; {'id': '376', 'type': 'call', 'children': ['377', '380']}, {'id': '377', 'type': 'attribute', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'C'}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'c_float'}; {'id': '380', 'type': 'argument_list', 'children': ['381']}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'fmax'}; {'id': '382', 'type': 'return_statement', 'children': ['383']}, {'id': '383', 'type': 'dictionary', 'children': ['384', '387', '390', '393', '396']}; {'id': '384', 'type': 'pair', 'children': ['385', '386']}, {'id': '385', 'type': 'string', 'children': [], 'value': '"frequencies"'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'freq'}, {'id': '387', 'type': 'pair', 'children': ['388', '389']}; {'id': '388', 'type': 'string', 'children': [], 'value': '"deconvolved"'}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'tfun'}; {'id': '390', 'type': 'pair', 'children': ['391', '392']}, {'id': '391', 'type': 'string', 'children': [], 'value': '"spectral_ratio"'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'spec_ratio'}, {'id': '393', 'type': 'pair', 'children': ['394', '395']}; {'id': '394', 'type': 'string', 'children': [], 'value': '"spectrum_a"'}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'speci'}; {'id': '396', 'type': 'pair', 'children': ['397', '398']}, {'id': '397', 'type': 'string', 'children': [], 'value': '"spectrum_b"'} | def mt_deconvolve(data_a, data_b, delta, nfft=None, time_bandwidth=None,
number_of_tapers=None, weights="adaptive", demean=True,
fmax=0.0):
npts = len(data_a)
if len(data_b) != npts:
raise ValueError("Input arrays must have the same length!")
if nfft is None:
nfft = npts
elif nfft < npts:
raise ValueError("nfft must be larger then the number of samples in "
"the array.")
mt = _MtspecType("float32")
if number_of_tapers is None:
number_of_tapers = int(2 * time_bandwidth) - 1
data_a = np.require(data_a, mt.float, requirements=[mt.order])
data_b = np.require(data_b, mt.float, requirements=[mt.order])
nf = nfft // 2 + 1
if demean:
demean = 1
else:
demean = 0
if weights == "constant":
adaptive = 1
elif weights == "adaptive":
adaptive = 0
else:
raise ValueError('Weights must be either "adaptive" or "constant".')
tfun = mt.empty(nfft)
freq = mt.empty(nf)
spec_ratio = mt.empty(nf)
speci = mt.empty(nf)
specj = mt.empty(nf)
mtspeclib.mt_deconv_(
C.byref(C.c_int(int(npts))),
C.byref(C.c_int(int(nfft))),
C.byref(C.c_float(float(delta))),
mt.p(data_a),
mt.p(data_b),
C.byref(C.c_float(float(time_bandwidth))),
C.byref(C.c_int(int(number_of_tapers))),
C.byref(C.c_int(int(nf))),
C.byref(C.c_int(adaptive)),
mt.p(freq),
mt.p(tfun),
mt.p(spec_ratio),
mt.p(speci),
mt.p(specj),
C.byref(C.c_int(demean)),
C.byref(C.c_float(fmax)))
return {
"frequencies": freq,
"deconvolved": tfun,
"spectral_ratio": spec_ratio,
"spectrum_a": speci,
"spectrum_b": specj
} |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_server'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'loop'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'as_coroutine'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'protocol_factory'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'dictionary_splat_pattern', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'server_config'}; {'id': '16', 'type': 'block', 'children': ['17', '33', '50', '67']}, {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '25']}; {'id': '22', 'type': 'import_statement', 'children': ['23']}, {'id': '23', 'type': 'dotted_name', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'asyncio'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'asyncio'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'get_event_loop'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'protocol_factory'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'block', 'children': ['38', '44']}; {'id': '38', 'type': 'import_from_statement', 'children': ['39', '42']}, {'id': '39', 'type': 'dotted_name', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'growler'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'aio'}; {'id': '42', 'type': 'dotted_name', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'GrowlerHTTPProtocol'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'protocol_factory'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'GrowlerHTTPProtocol'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get_factory'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'create_server'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'create_server'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '65']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'protocol_factory'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'loop'}, {'id': '65', 'type': 'dictionary_splat', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'server_config'}, {'id': '67', 'type': 'if_statement', 'children': ['68', '69', '72']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'as_coroutine'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'create_server'}; {'id': '72', 'type': 'else_clause', 'children': ['73']}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'loop'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'run_until_complete'}, {'id': '79', 'type': 'argument_list', 'children': ['80']} | def create_server(self,
loop=None,
as_coroutine=False,
protocol_factory=None,
**server_config):
if loop is None:
import asyncio
loop = asyncio.get_event_loop()
if protocol_factory is None:
from growler.aio import GrowlerHTTPProtocol
protocol_factory = GrowlerHTTPProtocol.get_factory
create_server = loop.create_server(
protocol_factory(self, loop=loop),
**server_config
)
if as_coroutine:
return create_server
else:
return loop.run_until_complete(create_server) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'event_emitter'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '8']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cls_'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'keyword_separator', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'events'}; {'id': '10', 'type': 'tuple', 'children': ['11']}, {'id': '11', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '12', 'type': 'block', 'children': ['13', '23', '35', '150']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'event_dict'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'fromkeys'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'events'}; {'id': '22', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'allow_any_eventname'}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '34'], 'value': '=='}, {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'event_dict'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'pop'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '33', 'type': 'False', 'children': []}; {'id': '34', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '35', 'type': 'function_definition', 'children': ['36', '37', '39']}; {'id': '36', 'type': 'function_name', 'children': [], 'value': '_event_emitter'}, {'id': '37', 'type': 'parameters', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '39', 'type': 'block', 'children': ['40', '109', '136', '142', '148']}; {'id': '40', 'type': 'function_definition', 'children': ['41', '42', '46']}, {'id': '41', 'type': 'function_name', 'children': [], 'value': 'on'}; {'id': '42', 'type': 'parameters', 'children': ['43', '44', '45']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '46', 'type': 'block', 'children': ['47', '67', '107']}, {'id': '47', 'type': 'if_statement', 'children': ['48', '59']}; {'id': '48', 'type': 'not_operator', 'children': ['49']}, {'id': '49', 'type': 'parenthesized_expression', 'children': ['50'], 'value': '()'}; {'id': '50', 'type': 'boolean_operator', 'children': ['51', '55'], 'value': 'or'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'callable'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'callback'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'isawaitable'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'callback'}, {'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': 'binary_operator', 'children': ['65', '66'], 'value': '%'}, {'id': '65', 'type': 'string', 'children': [], 'value': '"Callback not callable: %r"'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'callback'}, {'id': '67', 'type': 'try_statement', 'children': ['68', '78']}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'call', 'children': ['71', '76']}, {'id': '71', 'type': 'attribute', 'children': ['72', '75']}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'event_dict'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '78', 'type': 'except_clause', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'if_statement', 'children': ['82', '83', '91']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'allow_any_eventname'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '89']}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'event_dict'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '89', 'type': 'list', 'children': ['90'], 'value': '[callback]'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'callback'}, {'id': '91', 'type': 'else_clause', 'children': ['92']}; {'id': '92', 'type': 'block', 'children': ['93', '102']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': '"Event Emitter has no event {!r}"'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '102', 'type': 'raise_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '107', 'type': 'return_statement', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'function_definition', 'children': ['110', '111', '114']}; {'id': '110', 'type': 'function_name', 'children': [], 'value': 'emit'}, {'id': '111', 'type': 'parameters', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'for_statement', 'children': ['116', '117', '120']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'cb'}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'event_dict'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'if_statement', 'children': ['122', '126', '130']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'isawaitable'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'cb'}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'await', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'cb'}; {'id': '130', 'type': 'else_clause', 'children': ['131']}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'cb'}, {'id': '135', 'type': 'argument_list', 'children': []}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'on'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'on'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'emit'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'emit'}; {'id': '148', 'type': 'return_statement', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '150', 'type': 'if_statement', 'children': ['151', '154', '157']}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': 'is'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'cls_'}, {'id': '153', 'type': 'None', 'children': []}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'return_statement', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_event_emitter'}, {'id': '157', 'type': 'else_clause', 'children': ['158']}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'return_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': '_event_emitter'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'cls_'} | def event_emitter(cls_=None, *, events=('*', )):
event_dict = dict.fromkeys(events, [])
allow_any_eventname = event_dict.pop('*', False) == []
def _event_emitter(cls):
def on(self, name, callback):
if not (callable(callback) or isawaitable(callback)):
raise ValueError("Callback not callable: %r" % callback)
try:
event_dict[name].append(callback)
except KeyError:
if allow_any_eventname:
event_dict[name] = [callback]
else:
msg = "Event Emitter has no event {!r}".format(name)
raise KeyError(msg)
return self
async def emit(self, name):
for cb in event_dict[name]:
if isawaitable(cb):
await cb
else:
cb()
cls.on = on
cls.emit = emit
return cls
if cls_ is None:
return _event_emitter
else:
return _event_emitter(cls_) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_build_production_name'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '6', 'type': 'block', 'children': ['7', '32', '38', '56', '68', '103', '115', '157', '237']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_postscriptNames'}, {'id': '11', 'type': 'block', 'children': ['12', '25']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'production_name'}, {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_postscriptNames'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'conditional_expression', 'children': ['27', '28', '29'], 'value': 'if'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'production_name'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'production_name'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'unicode_val'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'unicode'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '44']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '43'], 'value': 'is'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'unicode'}, {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '%'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'%s%04X'"}; {'id': '48', 'type': 'tuple', 'children': ['49', '55']}, {'id': '49', 'type': 'conditional_expression', 'children': ['50', '51', '54'], 'value': 'if'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'u'"}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '>'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'unicode_val'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '0xffff'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'uni'"}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'unicode_val'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'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': 'glyph'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'rsplit'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '67', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '83']}, {'id': '69', 'type': 'boolean_operator', 'children': ['70', '76'], 'value': 'and'}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '75'], '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': 'identifier', 'children': [], 'value': 'parts'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '80'], 'value': 'in'}, {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '79', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'return_statement', 'children': ['85']}, {'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '%'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'%s.%s'"}, {'id': '87', 'type': 'tuple', 'children': ['88', '100']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': '_build_production_name'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'subscript', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '106', 'type': 'call', 'children': ['107', '112']}, {'id': '107', 'type': 'attribute', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114']}, {'id': '113', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '114', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '115', 'type': 'if_statement', 'children': ['116', '122', '144']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '121'], 'value': '=='}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'liga_parts'}; {'id': '126', 'type': 'list_comprehension', 'children': ['127', '134']}, {'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '%'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'%s.%s'"}, {'id': '129', 'type': 'tuple', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'parts'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '134', 'type': 'for_in_clause', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '136', 'type': 'call', 'children': ['137', '142']}, {'id': '137', 'type': 'attribute', 'children': ['138', '141']}; {'id': '138', 'type': 'subscript', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '140', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '144', 'type': 'else_clause', 'children': ['145']}, {'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': 'liga_parts'}, {'id': '149', 'type': 'call', 'children': ['150', '155']}; {'id': '150', 'type': 'attribute', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '157', 'type': 'if_statement', 'children': ['158', '176']}; {'id': '158', 'type': 'boolean_operator', 'children': ['159', '165'], 'value': 'and'}, {'id': '159', 'type': 'comparison_operator', 'children': ['160', '164'], 'value': '>'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'liga_parts'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'all'}, {'id': '167', 'type': 'generator_expression', 'children': ['168', '173']}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': 'in'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '173', 'type': 'for_in_clause', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'liga_parts'}; {'id': '176', 'type': 'block', 'children': ['177', '191', '218']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'unicode_vals'}; {'id': '180', 'type': 'list_comprehension', 'children': ['181', '188']}, {'id': '181', 'type': 'attribute', 'children': ['182', '187']}; {'id': '182', 'type': 'subscript', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'unicode'}; {'id': '188', 'type': 'for_in_clause', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'liga_parts'}, {'id': '191', 'type': 'if_statement', 'children': ['192', '203']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '194', 'type': 'generator_expression', 'children': ['195', '200']}, {'id': '195', 'type': 'boolean_operator', 'children': ['196', '197'], 'value': 'and'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': '<='}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '199', 'type': 'integer', 'children': [], 'value': '0xffff'}; {'id': '200', 'type': 'for_in_clause', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'unicode_vals'}, {'id': '203', 'type': 'block', 'children': ['204']}; {'id': '204', 'type': 'return_statement', 'children': ['205']}, {'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '+'}; {'id': '206', 'type': 'string', 'children': [], 'value': "'uni'"}, {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'string', 'children': [], 'value': "''"}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '211', 'type': 'generator_expression', 'children': ['212', '215']}; {'id': '212', 'type': 'binary_operator', 'children': ['213', '214'], 'value': '%'}, {'id': '213', 'type': 'string', 'children': [], 'value': "'%04X'"}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '215', 'type': 'for_in_clause', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'unicode_vals'}; {'id': '218', 'type': 'return_statement', 'children': ['219']}, {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '223', 'type': 'generator_expression', 'children': ['224', '234']}; {'id': '224', 'type': 'call', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': '_build_production_name'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'subscript', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '234', 'type': 'for_in_clause', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'liga_parts'}, {'id': '237', 'type': 'return_statement', 'children': ['238']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'glyph'} | def _build_production_name(self, glyph):
if self._postscriptNames:
production_name = self._postscriptNames.get(glyph.name)
return production_name if production_name else glyph.name
unicode_val = glyph.unicode
if glyph.unicode is not None:
return '%s%04X' % (
'u' if unicode_val > 0xffff else 'uni', unicode_val)
parts = glyph.name.rsplit('.', 1)
if len(parts) == 2 and parts[0] in self.glyphSet:
return '%s.%s' % (
self._build_production_name(self.glyphSet[parts[0]]), parts[1])
parts = glyph.name.split('.', 1)
if len(parts) == 2:
liga_parts = ['%s.%s' % (n, parts[1]) for n in parts[0].split('_')]
else:
liga_parts = glyph.name.split('_')
if len(liga_parts) > 1 and all(n in self.glyphSet for n in liga_parts):
unicode_vals = [self.glyphSet[n].unicode for n in liga_parts]
if all(v and v <= 0xffff for v in unicode_vals):
return 'uni' + ''.join('%04X' % v for v in unicode_vals)
return '_'.join(
self._build_production_name(self.glyphSet[n]) for n in liga_parts)
return glyph.name |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'makeOfficialGlyphOrder'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'glyphOrder'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '23', '34', '38', '57', '81', '91']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'glyphOrder'}; {'id': '12', 'type': 'None', 'children': []}, {'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': 'glyphOrder'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '19', 'type': 'argument_list', 'children': ['20', '21', '22']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '21', 'type': 'string', 'children': [], 'value': '"glyphOrder"'}; {'id': '22', 'type': 'tuple', 'children': []}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'order'}, {'id': '37', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'in'}; {'id': '40', 'type': 'string', 'children': [], 'value': '".notdef"'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '42', 'type': 'block', 'children': ['43', '50']}, {'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': 'names'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}, {'id': '49', 'type': 'string', 'children': [], 'value': '".notdef"'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'string', 'children': [], 'value': '".notdef"'}, {'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'glyphOrder'}; {'id': '60', 'type': 'block', 'children': ['61', '67', '74']}, {'id': '61', 'type': 'if_statement', 'children': ['62', '65']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'not'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'names'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'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': 'names'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'order'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'name'}, {'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': 'order'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'names'}, {'id': '91', 'type': 'return_statement', 'children': ['92']} | def makeOfficialGlyphOrder(font, glyphOrder=None):
if glyphOrder is None:
glyphOrder = getattr(font, "glyphOrder", ())
names = set(font.keys())
order = []
if ".notdef" in names:
names.remove(".notdef")
order.append(".notdef")
for name in glyphOrder:
if name not in names:
continue
names.remove(name)
order.append(name)
order.extend(sorted(names))
return order |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_layer'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'layerName'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'skipExportGlyphs'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'block', 'children': ['16', '39', '87', '190', '203']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20', '29']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'layerName'}, {'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': 'layer'}; {'id': '24', 'type': 'subscript', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'layers'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'layerName'}, {'id': '29', 'type': 'else_clause', 'children': ['30']}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'layer'}; {'id': '34', 'type': 'attribute', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'layers'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'defaultLayer'}, {'id': '39', 'type': 'if_statement', 'children': ['40', '41', '63']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '41', 'type': 'block', 'children': ['42', '52']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '_copyLayer'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'layer'}, {'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'obj_type'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'lib'}, {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'layer'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'lib'}, {'id': '63', 'type': 'else_clause', 'children': ['64']}; {'id': '64', 'type': 'block', 'children': ['65', '79']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '70', 'type': 'generator_expression', 'children': ['71', '76']}, {'id': '71', 'type': 'tuple', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '76', 'type': 'for_in_clause', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'layer'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'layer'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'lib'}, {'id': '87', 'type': 'if_statement', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'skipExportGlyphs'}, {'id': '89', 'type': 'block', 'children': ['90', '177']}; {'id': '90', 'type': 'for_statement', 'children': ['91', '92', '97']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '96', 'type': 'argument_list', 'children': []}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'if_statement', 'children': ['99', '112']}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'any'}, {'id': '101', 'type': 'generator_expression', 'children': ['102', '107']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '106'], 'value': 'in'}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'baseGlyph'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'skipExportGlyphs'}, {'id': '107', 'type': 'for_in_clause', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'components'}; {'id': '112', 'type': 'block', 'children': ['113', '124']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'deepCopyContours'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118', '119', '120', '123']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'Transform'}; {'id': '122', 'type': 'argument_list', 'children': []}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'skipExportGlyphs'}; {'id': '124', 'type': 'if_statement', 'children': ['125', '130', '154']}, {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '129', 'type': 'string', 'children': [], 'value': '"removeComponent"'}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'for_statement', 'children': ['132', '133', '146']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '133', 'type': 'list_comprehension', 'children': ['134', '135', '140']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '135', 'type': 'for_in_clause', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'components'}; {'id': '140', 'type': 'if_clause', 'children': ['141']}, {'id': '141', 'type': 'comparison_operator', 'children': ['142', '145'], 'value': 'in'}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'baseGlyph'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'skipExportGlyphs'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'removeComponent'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '154', 'type': 'else_clause', 'children': ['155']}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '164']}; {'id': '158', 'type': 'subscript', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'components'}; {'id': '162', 'type': 'slice', 'children': ['163']}, {'id': '163', 'type': 'colon', 'children': []}; {'id': '164', 'type': 'list_comprehension', 'children': ['165', '166', '171']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '166', 'type': 'for_in_clause', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'components'}, {'id': '171', 'type': 'if_clause', 'children': ['172']}; {'id': '172', 'type': 'comparison_operator', 'children': ['173', '176'], 'value': 'not'}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'baseGlyph'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'skipExportGlyphs'}, {'id': '177', 'type': 'for_statement', 'children': ['178', '179', '180']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'glyph_name'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'skipExportGlyphs'}; {'id': '180', 'type': 'block', 'children': ['181']}, {'id': '181', 'type': 'if_statement', 'children': ['182', '185']}; {'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': 'in'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'glyph_name'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'delete_statement', 'children': ['187']}, {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'glyph_name'}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '195', 'type': 'conditional_expression', 'children': ['196', '199', '202'], 'value': 'if'}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'layer'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': 'is'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'layerName'}, {'id': '201', 'type': 'None', 'children': []}; {'id': '202', 'type': 'None', 'children': []}, {'id': '203', 'type': 'return_statement', 'children': ['204']} | def from_layer(cls, font, layerName=None, copy=False, skipExportGlyphs=None):
if layerName is not None:
layer = font.layers[layerName]
else:
layer = font.layers.defaultLayer
if copy:
self = _copyLayer(layer, obj_type=cls)
self.lib = deepcopy(layer.lib)
else:
self = cls((g.name, g) for g in layer)
self.lib = layer.lib
if skipExportGlyphs:
for glyph in self.values():
if any(c.baseGlyph in skipExportGlyphs for c in glyph.components):
deepCopyContours(self, glyph, glyph, Transform(), skipExportGlyphs)
if hasattr(glyph, "removeComponent"):
for c in [
component
for component in glyph.components
if component.baseGlyph in skipExportGlyphs
]:
glyph.removeComponent(c)
else:
glyph.components[:] = [
c
for c in glyph.components
if c.baseGlyph not in skipExportGlyphs
]
for glyph_name in skipExportGlyphs:
if glyph_name in self:
del self[glyph_name]
self.name = layer.name if layerName is not None else None
return self |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '38']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'compileInterpolatableTTFs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ufos'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'preProcessorClass'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'TTFInterpolatablePreProcessor'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'outlineCompilerClass'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'OutlineTTFCompiler'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'featureCompilerClass'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'featureWriters'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'glyphOrder'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'useProductionNames'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'cubicConversionError'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'reverseDirection'}; {'id': '28', 'type': 'True', 'children': []}, {'id': '29', 'type': 'default_parameter', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'inplace'}, {'id': '31', 'type': 'False', 'children': []}; {'id': '32', 'type': 'default_parameter', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'layerNames'}; {'id': '34', 'type': 'None', 'children': []}, {'id': '35', 'type': 'default_parameter', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'skipExportGlyphs'}, {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'block', 'children': ['39', '45', '60', '70', '100', '107', '129', '137']}, {'id': '39', 'type': 'import_from_statement', 'children': ['40', '43']}; {'id': '40', 'type': 'dotted_name', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ufo2ft'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'util'}, {'id': '43', 'type': 'dotted_name', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_LazyFontName'}, {'id': '45', 'type': 'if_statement', 'children': ['46', '49']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'layerNames'}; {'id': '48', 'type': 'None', 'children': []}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'layerNames'}, {'id': '53', 'type': 'binary_operator', 'children': ['54', '56'], 'value': '*'}; {'id': '54', 'type': 'list', 'children': ['55'], 'value': '[None]'}, {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ufos'}; {'id': '60', 'type': 'assert_statement', 'children': ['61']}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '66'], 'value': '=='}; {'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': 'ufos'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'layerNames'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '74']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'is'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'skipExportGlyphs'}, {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'block', 'children': ['75', '81']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'skipExportGlyphs'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '80', 'type': 'argument_list', 'children': []}, {'id': '81', 'type': 'for_statement', 'children': ['82', '83', '84']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ufo'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ufos'}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'skipExportGlyphs'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '97']}; {'id': '92', 'type': 'attribute', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'ufo'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'lib'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': '"public.skipExportGlyphs"'}, {'id': '99', 'type': 'list', 'children': [], 'value': '[]'}; {'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': 'logger'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'string', 'children': [], 'value': '"Pre-processing glyphs"'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'preProcessor'}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'preProcessorClass'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114', '117', '120', '123', '126']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'ufos'}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'inplace'}, {'id': '117', 'type': 'keyword_argument', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'conversionError'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'cubicConversionError'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'reverseDirection'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'reverseDirection'}, {'id': '123', 'type': 'keyword_argument', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'layerNames'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'layerNames'}; {'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'skipExportGlyphs'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'skipExportGlyphs'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'glyphSets'}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'preProcessor'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '136', 'type': 'argument_list', 'children': []}, {'id': '137', 'type': 'for_statement', 'children': ['138', '142', '148']}; {'id': '138', 'type': 'pattern_list', 'children': ['139', '140', '141']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'ufo'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'layerName'}; {'id': '142', 'type': 'call', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146', '147']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'ufos'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'glyphSets'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'layerNames'}; {'id': '148', 'type': 'block', 'children': ['149', '156', '180', '199', '207', '227', '238', '247', '270']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'fontName'}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': '_LazyFontName'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'ufo'}; {'id': '156', 'type': 'if_statement', 'children': ['157', '160', '170']}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': 'is'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'layerName'}, {'id': '159', 'type': 'None', 'children': []}; {'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': 'logger'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '168', '169']}, {'id': '167', 'type': 'string', 'children': [], 'value': '"Building OpenType tables for %s-%s"'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'fontName'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'layerName'}; {'id': '170', 'type': 'else_clause', 'children': ['171']}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '177', 'type': 'argument_list', 'children': ['178', '179']}; {'id': '178', 'type': 'string', 'children': [], 'value': '"Building OpenType tables for %s"'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'fontName'}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'outlineCompiler'}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'outlineCompilerClass'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '187', '190', '193']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'ufo'}, {'id': '187', 'type': 'keyword_argument', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}; {'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'glyphOrder'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'glyphOrder'}, {'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'tables'}, {'id': '195', 'type': 'conditional_expression', 'children': ['196', '197', '198'], 'value': 'if'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'SPARSE_TTF_MASTER_TABLES'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'layerName'}; {'id': '198', 'type': 'None', 'children': []}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'ttf'}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'outlineCompiler'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'compile'}; {'id': '206', 'type': 'argument_list', 'children': []}, {'id': '207', 'type': 'if_statement', 'children': ['208', '211']}; {'id': '208', 'type': 'comparison_operator', 'children': ['209', '210'], 'value': 'is'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'layerName'}; {'id': '210', 'type': 'None', 'children': []}, {'id': '211', 'type': 'block', 'children': ['212']}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'compileFeatures'}, {'id': '215', 'type': 'argument_list', 'children': ['216', '217', '218', '221', '224']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'ufo'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'ttf'}; {'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'featureWriters'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'featureWriters'}; {'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'featureCompilerClass'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'featureCompilerClass'}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'postProcessor'}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'PostProcessor'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '234', '235']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'ttf'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'ufo'}, {'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'assignment', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'ttf'}, {'id': '241', 'type': 'call', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'postProcessor'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'process'}, {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'useProductionNames'}, {'id': '247', 'type': 'if_statement', 'children': ['248', '251']}; {'id': '248', 'type': 'comparison_operator', 'children': ['249', '250'], 'value': 'is'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'layerName'}; {'id': '250', 'type': 'None', 'children': []}, {'id': '251', 'type': 'block', 'children': ['252', '261']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'assignment', 'children': ['254', '259']}; {'id': '254', 'type': 'attribute', 'children': ['255', '258']}, {'id': '255', 'type': 'subscript', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'ttf'}, {'id': '257', 'type': 'string', 'children': [], 'value': '"post"'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'underlinePosition'}, {'id': '259', 'type': 'unary_operator', 'children': ['260'], 'value': '-'}; {'id': '260', 'type': 'integer', 'children': [], 'value': '0x8000'}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '268']}, {'id': '263', 'type': 'attribute', 'children': ['264', '267']}; {'id': '264', 'type': 'subscript', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'ttf'}; {'id': '266', 'type': 'string', 'children': [], 'value': '"post"'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'underlineThickness'}; {'id': '268', 'type': 'unary_operator', 'children': ['269'], 'value': '-'}, {'id': '269', 'type': 'integer', 'children': [], 'value': '0x8000'}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'yield', 'children': ['272']} | def compileInterpolatableTTFs(
ufos,
preProcessorClass=TTFInterpolatablePreProcessor,
outlineCompilerClass=OutlineTTFCompiler,
featureCompilerClass=None,
featureWriters=None,
glyphOrder=None,
useProductionNames=None,
cubicConversionError=None,
reverseDirection=True,
inplace=False,
layerNames=None,
skipExportGlyphs=None,
):
from ufo2ft.util import _LazyFontName
if layerNames is None:
layerNames = [None] * len(ufos)
assert len(ufos) == len(layerNames)
if skipExportGlyphs is None:
skipExportGlyphs = set()
for ufo in ufos:
skipExportGlyphs.update(ufo.lib.get("public.skipExportGlyphs", []))
logger.info("Pre-processing glyphs")
preProcessor = preProcessorClass(
ufos,
inplace=inplace,
conversionError=cubicConversionError,
reverseDirection=reverseDirection,
layerNames=layerNames,
skipExportGlyphs=skipExportGlyphs,
)
glyphSets = preProcessor.process()
for ufo, glyphSet, layerName in zip(ufos, glyphSets, layerNames):
fontName = _LazyFontName(ufo)
if layerName is not None:
logger.info("Building OpenType tables for %s-%s", fontName, layerName)
else:
logger.info("Building OpenType tables for %s", fontName)
outlineCompiler = outlineCompilerClass(
ufo,
glyphSet=glyphSet,
glyphOrder=glyphOrder,
tables=SPARSE_TTF_MASTER_TABLES if layerName else None,
)
ttf = outlineCompiler.compile()
if layerName is None:
compileFeatures(
ufo,
ttf,
glyphSet=glyphSet,
featureWriters=featureWriters,
featureCompilerClass=featureCompilerClass,
)
postProcessor = PostProcessor(ttf, ufo, glyphSet=glyphSet)
ttf = postProcessor.process(useProductionNames)
if layerName is not None:
ttf["post"].underlinePosition = -0x8000
ttf["post"].underlineThickness = -0x8000
yield ttf |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_propagate_glyph_anchors'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'composite'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'processed'}, {'id': '7', 'type': 'block', 'children': ['8', '16', '25', '32', '36', '40', '46', '50', '143', '222', '253', '264']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '14']}, {'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': 'in'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'composite'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'processed'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'return_statement', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'processed'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'composite'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '30']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'composite'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'components'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'return_statement', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'base_components'}, {'id': '35', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'mark_components'}, {'id': '39', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'anchor_names'}, {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'to_add'}, {'id': '49', 'type': 'dictionary', 'children': []}; {'id': '50', 'type': 'for_statement', 'children': ['51', '52', '55']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'composite'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'components'}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'try_statement', 'children': ['57', '66', '88']}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'baseGlyph'}; {'id': '66', 'type': 'except_clause', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'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': 'logger'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '81']}; {'id': '76', 'type': 'attribute', 'children': ['77', '80']}, {'id': '77', 'type': 'concatenated_string', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': "'Anchors not propagated for inexistent component {} '"}, {'id': '79', 'type': 'string', 'children': [], 'value': "'in glyph {}'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'baseGlyph'}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'composite'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '88', 'type': 'else_clause', 'children': ['89']}, {'id': '89', 'type': 'block', 'children': ['90', '97']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_propagate_glyph_anchors'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95', '96']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'processed'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '114', '122']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '100', 'type': 'generator_expression', 'children': ['101', '109']}, {'id': '101', 'type': 'call', 'children': ['102', '107']}; {'id': '102', 'type': 'attribute', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '109', 'type': 'for_in_clause', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'anchors'}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'mark_components'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '122', 'type': 'else_clause', 'children': ['123']}, {'id': '123', 'type': 'block', 'children': ['124', '131']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'base_components'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'augmented_assignment', 'children': ['133', '134'], 'value': '|='}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'anchor_names'}; {'id': '134', 'type': 'set_comprehension', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '138', 'type': 'for_in_clause', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'anchors'}, {'id': '143', 'type': 'if_statement', 'children': ['144', '153']}; {'id': '144', 'type': 'boolean_operator', 'children': ['145', '149'], 'value': 'and'}, {'id': '145', 'type': 'boolean_operator', 'children': ['146', '147'], 'value': 'and'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'mark_components'}, {'id': '147', 'type': 'not_operator', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'base_components'}, {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': '_is_ligature_mark'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'composite'}, {'id': '153', 'type': 'block', 'children': ['154', '188', '195', '202', '210']}; {'id': '154', 'type': 'try_statement', 'children': ['155', '164']}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': '_component_closest_to_origin'}, {'id': '161', 'type': 'argument_list', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'mark_components'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}; {'id': '164', 'type': 'except_clause', 'children': ['165', '169']}, {'id': '165', 'type': 'as_pattern', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '167', 'type': 'as_pattern_target', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'e'}, {'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': 'Exception'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '180']}, {'id': '175', 'type': 'attribute', 'children': ['176', '179']}; {'id': '176', 'type': 'concatenated_string', 'children': ['177', '178']}, {'id': '177', 'type': 'string', 'children': [], 'value': '"Error while determining which component of composite "'}; {'id': '178', 'type': 'string', 'children': [], 'value': '"\'{}\' is the lowest: {}"'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '180', 'type': 'argument_list', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'composite'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'mark_components'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'base_components'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '205', 'type': 'subscript', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'baseGlyph'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'augmented_assignment', 'children': ['212', '213'], 'value': '|='}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'anchor_names'}, {'id': '213', 'type': 'set_comprehension', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '217', 'type': 'for_in_clause', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'glyph'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'anchors'}; {'id': '222', 'type': 'for_statement', 'children': ['223', '224', '225']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'anchor_name'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'anchor_names'}, {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'if_statement', 'children': ['227', '244']}, {'id': '227', 'type': 'not_operator', 'children': ['228']}; {'id': '228', 'type': 'call', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '230', 'type': 'generator_expression', 'children': ['231', '239']}, {'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': 'a'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'anchor_name'}, {'id': '239', 'type': 'for_in_clause', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'composite'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'anchors'}; {'id': '244', 'type': 'block', 'children': ['245']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': '_get_anchor_data'}; {'id': '248', 'type': 'argument_list', 'children': ['249', '250', '251', '252']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'to_add'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'base_components'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'anchor_name'}, {'id': '253', 'type': 'for_statement', 'children': ['254', '255', '256']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'component'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'mark_components'}; {'id': '256', 'type': 'block', 'children': ['257']}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'call', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': '_adjust_anchors'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '262', '263']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'to_add'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'glyphSet'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'component'}; {'id': '264', 'type': 'for_statement', 'children': ['265', '270', '278']}, {'id': '265', 'type': 'pattern_list', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '267', 'type': 'tuple_pattern', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '270', 'type': 'call', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'to_add'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '277', 'type': 'argument_list', 'children': []}; {'id': '278', 'type': 'block', 'children': ['279', '292']}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'anchor_dict'}; {'id': '282', 'type': 'dictionary', 'children': ['283', '286', '289']}, {'id': '283', 'type': 'pair', 'children': ['284', '285']}; {'id': '284', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '286', 'type': 'pair', 'children': ['287', '288']}, {'id': '287', 'type': 'string', 'children': [], 'value': "'x'"}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '289', 'type': 'pair', 'children': ['290', '291']}; {'id': '290', 'type': 'string', 'children': [], 'value': "'y'"}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '292', 'type': 'try_statement', 'children': ['293', '301']}, {'id': '293', 'type': 'block', 'children': ['294']}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}, {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'composite'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'appendAnchor'}, {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'anchor_dict'}, {'id': '301', 'type': 'except_clause', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '303', 'type': 'block', 'children': ['304']}; {'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': 'composite'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'appendAnchor'}, {'id': '309', 'type': 'argument_list', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '311', 'type': 'tuple', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'y'} | def _propagate_glyph_anchors(glyphSet, composite, processed):
if composite.name in processed:
return
processed.add(composite.name)
if not composite.components:
return
base_components = []
mark_components = []
anchor_names = set()
to_add = {}
for component in composite.components:
try:
glyph = glyphSet[component.baseGlyph]
except KeyError:
logger.warning(
'Anchors not propagated for inexistent component {} '
'in glyph {}'.format(component.baseGlyph, composite.name))
else:
_propagate_glyph_anchors(glyphSet, glyph, processed)
if any(a.name.startswith('_') for a in glyph.anchors):
mark_components.append(component)
else:
base_components.append(component)
anchor_names |= {a.name for a in glyph.anchors}
if mark_components and not base_components and _is_ligature_mark(composite):
try:
component = _component_closest_to_origin(mark_components, glyphSet)
except Exception as e:
raise Exception(
"Error while determining which component of composite "
"'{}' is the lowest: {}".format(composite.name, str(e))
)
mark_components.remove(component)
base_components.append(component)
glyph = glyphSet[component.baseGlyph]
anchor_names |= {a.name for a in glyph.anchors}
for anchor_name in anchor_names:
if not any(a.name.startswith(anchor_name) for a in composite.anchors):
_get_anchor_data(to_add, glyphSet, base_components, anchor_name)
for component in mark_components:
_adjust_anchors(to_add, glyphSet, component)
for name, (x, y) in sorted(to_add.items()):
anchor_dict = {'name': name, 'x': x, 'y': y}
try:
composite.appendAnchor(anchor_dict)
except TypeError:
composite.appendAnchor(name, (x, y)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setupTable_name'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '20', '33', '39', '96', '106', '120', '130', '140', '148', '275', '288', '301', '317']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'not'}; {'id': '8', 'type': 'string', 'children': [], 'value': '"name"'}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'tables'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'ufo'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '27']}; {'id': '22', 'type': 'subscript', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'otf'}; {'id': '26', 'type': 'string', 'children': [], 'value': '"name"'}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'newTable'}, {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'string', 'children': [], 'value': '"name"'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '38', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '39', 'type': 'for_statement', 'children': ['40', '41', '48']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'nameRecord'}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '47', 'type': 'string', 'children': [], 'value': '"openTypeNameRecords"'}; {'id': '48', 'type': 'block', 'children': ['49', '55', '61', '67', '73', '85']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'nameId'}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'nameRecord'}; {'id': '54', 'type': 'string', 'children': [], 'value': '"nameID"'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'platformId'}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'nameRecord'}; {'id': '60', 'type': 'string', 'children': [], 'value': '"platformID"'}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'platEncId'}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'nameRecord'}; {'id': '66', 'type': 'string', 'children': [], 'value': '"encodingID"'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'langId'}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'nameRecord'}; {'id': '72', 'type': 'string', 'children': [], 'value': '"languageID"'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'nameVal'}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'tounicode'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '82']}, {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'nameRecord'}, {'id': '81', 'type': 'string', 'children': [], 'value': '"string"'}; {'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'ascii'"}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'setName'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92', '93', '94', '95']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'nameVal'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'nameId'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'platformId'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'platEncId'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'langId'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'familyName'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '105', 'type': 'string', 'children': [], 'value': '"styleMapFamilyName"'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'styleName'}, {'id': '109', 'type': 'call', 'children': ['110', '119']}; {'id': '110', 'type': 'attribute', 'children': ['111', '118']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '117', 'type': 'string', 'children': [], 'value': '"styleMapStyleName"'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '119', 'type': 'argument_list', 'children': []}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'preferredFamilyName'}, {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '129', 'type': 'string', 'children': [], 'value': '"openTypeNamePreferredFamilyName"'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'preferredSubfamilyName'}, {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}, {'id': '135', 'type': 'argument_list', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '139', 'type': 'string', 'children': [], 'value': '"openTypeNamePreferredSubfamilyName"'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'fullName'}, {'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '%'}; {'id': '144', 'type': 'string', 'children': [], 'value': '"%s %s"'}, {'id': '145', 'type': 'tuple', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'preferredFamilyName'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'preferredSubfamilyName'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'nameVals'}, {'id': '151', 'type': 'dictionary', 'children': ['152', '161', '164', '167', '176', '179', '188', '197', '206', '215', '224', '233', '242', '251', '260', '269', '272']}; {'id': '152', 'type': 'pair', 'children': ['153', '154']}, {'id': '153', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '154', 'type': 'call', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '160', 'type': 'string', 'children': [], 'value': '"copyright"'}, {'id': '161', 'type': 'pair', 'children': ['162', '163']}; {'id': '162', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'familyName'}; {'id': '164', 'type': 'pair', 'children': ['165', '166']}, {'id': '165', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'styleName'}, {'id': '167', 'type': 'pair', 'children': ['168', '169']}; {'id': '168', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}, {'id': '171', 'type': 'argument_list', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '175', 'type': 'string', 'children': [], 'value': '"openTypeNameUniqueID"'}; {'id': '176', 'type': 'pair', 'children': ['177', '178']}, {'id': '177', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'fullName'}, {'id': '179', 'type': 'pair', 'children': ['180', '181']}; {'id': '180', 'type': 'integer', 'children': [], 'value': '5'}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}, {'id': '183', 'type': 'argument_list', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '187', 'type': 'string', 'children': [], 'value': '"openTypeNameVersion"'}; {'id': '188', 'type': 'pair', 'children': ['189', '190']}, {'id': '189', 'type': 'integer', 'children': [], 'value': '6'}; {'id': '190', 'type': 'call', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '196', 'type': 'string', 'children': [], 'value': '"postscriptFontName"'}, {'id': '197', 'type': 'pair', 'children': ['198', '199']}; {'id': '198', 'type': 'integer', 'children': [], 'value': '7'}, {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}, {'id': '201', 'type': 'argument_list', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '205', 'type': 'string', 'children': [], 'value': '"trademark"'}; {'id': '206', 'type': 'pair', 'children': ['207', '208']}, {'id': '207', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}; {'id': '210', 'type': 'argument_list', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '214', 'type': 'string', 'children': [], 'value': '"openTypeNameManufacturer"'}, {'id': '215', 'type': 'pair', 'children': ['216', '217']}; {'id': '216', 'type': 'integer', 'children': [], 'value': '9'}, {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}, {'id': '219', 'type': 'argument_list', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '223', 'type': 'string', 'children': [], 'value': '"openTypeNameDesigner"'}; {'id': '224', 'type': 'pair', 'children': ['225', '226']}, {'id': '225', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '226', 'type': 'call', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}; {'id': '228', 'type': 'argument_list', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '232', 'type': 'string', 'children': [], 'value': '"openTypeNameDescription"'}, {'id': '233', 'type': 'pair', 'children': ['234', '235']}; {'id': '234', 'type': 'integer', 'children': [], 'value': '11'}, {'id': '235', 'type': 'call', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}, {'id': '237', 'type': 'argument_list', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '241', 'type': 'string', 'children': [], 'value': '"openTypeNameManufacturerURL"'}; {'id': '242', 'type': 'pair', 'children': ['243', '244']}, {'id': '243', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}; {'id': '246', 'type': 'argument_list', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '250', 'type': 'string', 'children': [], 'value': '"openTypeNameDesignerURL"'}, {'id': '251', 'type': 'pair', 'children': ['252', '253']}; {'id': '252', 'type': 'integer', 'children': [], 'value': '13'}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}, {'id': '255', 'type': 'argument_list', 'children': ['256', '259']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '259', 'type': 'string', 'children': [], 'value': '"openTypeNameLicense"'}; {'id': '260', 'type': 'pair', 'children': ['261', '262']}, {'id': '261', 'type': 'integer', 'children': [], 'value': '14'}; {'id': '262', 'type': 'call', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}; {'id': '264', 'type': 'argument_list', 'children': ['265', '268']}, {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '268', 'type': 'string', 'children': [], 'value': '"openTypeNameLicenseURL"'}, {'id': '269', 'type': 'pair', 'children': ['270', '271']}; {'id': '270', 'type': 'integer', 'children': [], 'value': '16'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'preferredFamilyName'}; {'id': '272', 'type': 'pair', 'children': ['273', '274']}, {'id': '273', 'type': 'integer', 'children': [], 'value': '17'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'preferredSubfamilyName'}, {'id': '275', 'type': 'if_statement', 'children': ['276', '283']}; {'id': '276', 'type': 'comparison_operator', 'children': ['277', '280'], 'value': '=='}, {'id': '277', 'type': 'subscript', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'nameVals'}, {'id': '279', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '280', 'type': 'subscript', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'nameVals'}; {'id': '282', 'type': 'integer', 'children': [], 'value': '16'}, {'id': '283', 'type': 'block', 'children': ['284']}; {'id': '284', 'type': 'delete_statement', 'children': ['285']}, {'id': '285', 'type': 'subscript', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'nameVals'}, {'id': '287', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '288', 'type': 'if_statement', 'children': ['289', '296']}, {'id': '289', 'type': 'comparison_operator', 'children': ['290', '293'], 'value': '=='}; {'id': '290', 'type': 'subscript', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'nameVals'}; {'id': '292', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '293', 'type': 'subscript', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'nameVals'}, {'id': '295', 'type': 'integer', 'children': [], 'value': '17'}; {'id': '296', 'type': 'block', 'children': ['297']}, {'id': '297', 'type': 'delete_statement', 'children': ['298']}; {'id': '298', 'type': 'subscript', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'nameVals'}; {'id': '300', 'type': 'integer', 'children': [], 'value': '17'}, {'id': '301', 'type': 'if_statement', 'children': ['302', '305']}; {'id': '302', 'type': 'subscript', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'nameVals'}; {'id': '304', 'type': 'integer', 'children': [], 'value': '6'}, {'id': '305', 'type': 'block', 'children': ['306']}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'assignment', 'children': ['308', '311']}; {'id': '308', 'type': 'subscript', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'nameVals'}; {'id': '310', 'type': 'integer', 'children': [], 'value': '6'}, {'id': '311', 'type': 'call', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'normalizeStringForPostscript'}, {'id': '313', 'type': 'argument_list', 'children': ['314']}; {'id': '314', 'type': 'subscript', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'nameVals'}; {'id': '316', 'type': 'integer', 'children': [], 'value': '6'}, {'id': '317', 'type': 'for_statement', 'children': ['318', '319', '327']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'nameId'}, {'id': '319', 'type': 'call', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'call', 'children': ['323', '326']}, {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'nameVals'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '326', 'type': 'argument_list', 'children': []}, {'id': '327', 'type': 'block', 'children': ['328', '334', '339', '349', '353', '363', '367', '379']}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'assignment', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'nameVal'}, {'id': '331', 'type': 'subscript', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'nameVals'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'nameId'}; {'id': '334', 'type': 'if_statement', 'children': ['335', '337']}, {'id': '335', 'type': 'not_operator', 'children': ['336']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'nameVal'}, {'id': '337', 'type': 'block', 'children': ['338']}; {'id': '338', 'type': 'continue_statement', 'children': []}, {'id': '339', 'type': 'expression_statement', 'children': ['340']}; {'id': '340', 'type': 'assignment', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'nameVal'}; {'id': '342', 'type': 'call', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'tounicode'}; {'id': '344', 'type': 'argument_list', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'nameVal'}; {'id': '346', 'type': 'keyword_argument', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '348', 'type': 'string', 'children': [], 'value': "'ascii'"}, {'id': '349', 'type': 'expression_statement', 'children': ['350']}; {'id': '350', 'type': 'assignment', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'platformId'}; {'id': '352', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '353', 'type': 'expression_statement', 'children': ['354']}; {'id': '354', 'type': 'assignment', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'platEncId'}; {'id': '356', 'type': 'conditional_expression', 'children': ['357', '358', '362'], 'value': 'if'}, {'id': '357', 'type': 'integer', 'children': [], 'value': '10'}; {'id': '358', 'type': 'call', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': '_isNonBMP'}; {'id': '360', 'type': 'argument_list', 'children': ['361']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'nameVal'}; {'id': '362', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '363', 'type': 'expression_statement', 'children': ['364']}; {'id': '364', 'type': 'assignment', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'langId'}; {'id': '366', 'type': 'integer', 'children': [], 'value': '0x409'}, {'id': '367', 'type': 'if_statement', 'children': ['368', '377']}; {'id': '368', 'type': 'call', 'children': ['369', '372']}, {'id': '369', 'type': 'attribute', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'getName'}; {'id': '372', 'type': 'argument_list', 'children': ['373', '374', '375', '376']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'nameId'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'platformId'}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'platEncId'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'langId'}, {'id': '377', 'type': 'block', 'children': ['378']}; {'id': '378', 'type': 'continue_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': 'name'}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'setName'}; {'id': '384', 'type': 'argument_list', 'children': ['385', '386', '387', '388', '389']}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'nameVal'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'nameId'}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'platformId'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'platEncId'}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'langId'} | def setupTable_name(self):
if "name" not in self.tables:
return
font = self.ufo
self.otf["name"] = name = newTable("name")
name.names = []
for nameRecord in getAttrWithFallback(
font.info, "openTypeNameRecords"):
nameId = nameRecord["nameID"]
platformId = nameRecord["platformID"]
platEncId = nameRecord["encodingID"]
langId = nameRecord["languageID"]
nameVal = tounicode(nameRecord["string"], encoding='ascii')
name.setName(nameVal, nameId, platformId, platEncId, langId)
familyName = getAttrWithFallback(font.info, "styleMapFamilyName")
styleName = getAttrWithFallback(font.info, "styleMapStyleName").title()
preferredFamilyName = getAttrWithFallback(
font.info, "openTypeNamePreferredFamilyName")
preferredSubfamilyName = getAttrWithFallback(
font.info, "openTypeNamePreferredSubfamilyName")
fullName = "%s %s" % (preferredFamilyName, preferredSubfamilyName)
nameVals = {
0: getAttrWithFallback(font.info, "copyright"),
1: familyName,
2: styleName,
3: getAttrWithFallback(font.info, "openTypeNameUniqueID"),
4: fullName,
5: getAttrWithFallback(font.info, "openTypeNameVersion"),
6: getAttrWithFallback(font.info, "postscriptFontName"),
7: getAttrWithFallback(font.info, "trademark"),
8: getAttrWithFallback(font.info, "openTypeNameManufacturer"),
9: getAttrWithFallback(font.info, "openTypeNameDesigner"),
10: getAttrWithFallback(font.info, "openTypeNameDescription"),
11: getAttrWithFallback(font.info, "openTypeNameManufacturerURL"),
12: getAttrWithFallback(font.info, "openTypeNameDesignerURL"),
13: getAttrWithFallback(font.info, "openTypeNameLicense"),
14: getAttrWithFallback(font.info, "openTypeNameLicenseURL"),
16: preferredFamilyName,
17: preferredSubfamilyName,
}
if nameVals[1] == nameVals[16]:
del nameVals[16]
if nameVals[2] == nameVals[17]:
del nameVals[17]
if nameVals[6]:
nameVals[6] = normalizeStringForPostscript(nameVals[6])
for nameId in sorted(nameVals.keys()):
nameVal = nameVals[nameId]
if not nameVal:
continue
nameVal = tounicode(nameVal, encoding='ascii')
platformId = 3
platEncId = 10 if _isNonBMP(nameVal) else 1
langId = 0x409
if name.getName(nameId, platformId, platEncId, langId):
continue
name.setName(nameVal, nameId, platformId, platEncId, langId) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setupTable_cmap'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '22', '46', '84', '91', '97', '103', '109', '115', '122', '128', '134', '140', '146', '159', '165', '173']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '12']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'not'}; {'id': '8', 'type': 'string', 'children': [], 'value': '"cmap"'}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'tables'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'return_statement', 'children': []}; {'id': '14', 'type': 'import_from_statement', 'children': ['15', '20']}, {'id': '15', 'type': 'dotted_name', 'children': ['16', '17', '18', '19']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'fontTools'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ttLib'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'tables'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '_c_m_a_p'}; {'id': '20', 'type': 'dotted_name', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cmap_format_4'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'nonBMP'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '27', 'type': 'generator_expression', 'children': ['28', '31', '42']}; {'id': '28', 'type': 'tuple', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '31', 'type': 'for_in_clause', 'children': ['32', '35']}; {'id': '32', 'type': 'pattern_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'v'}, {'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': 'unicodeToGlyphNameMapping'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'if_clause', 'children': ['43']}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': '>'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '65535'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '48', '73']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'nonBMP'}; {'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': 'mapping'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '54', 'type': 'generator_expression', 'children': ['55', '58', '69']}, {'id': '55', 'type': 'tuple', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '58', 'type': 'for_in_clause', 'children': ['59', '62']}, {'id': '59', 'type': 'pattern_list', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '62', 'type': 'call', 'children': ['63', '68']}, {'id': '63', 'type': 'attribute', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'unicodeToGlyphNameMapping'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '68', 'type': 'argument_list', 'children': []}, {'id': '69', 'type': 'if_clause', 'children': ['70']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': '<='}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '65535'}, {'id': '73', 'type': 'else_clause', 'children': ['74']}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'unicodeToGlyphNameMapping'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'cmap4_0_3'}, {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'cmap_format_4'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'cmap4_0_3'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'platformID'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'cmap4_0_3'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'platEncID'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'cmap4_0_3'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'language'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'cmap4_0_3'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'mapping'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'cmap4_3_1'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'cmap_format_4'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'cmap4_3_1'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'platformID'}, {'id': '127', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'cmap4_3_1'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'platEncID'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'cmap4_3_1'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'language'}, {'id': '139', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'cmap4_3_1'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'cmap'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '153']}; {'id': '148', 'type': 'subscript', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'otf'}; {'id': '152', 'type': 'string', 'children': [], 'value': '"cmap"'}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'cmap'}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'newTable'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'string', 'children': [], 'value': '"cmap"'}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'cmap'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'tableVersion'}; {'id': '164', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'cmap'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'tables'}; {'id': '170', 'type': 'list', 'children': ['171', '172'], 'value': '[cmap4_0_3, cmap4_3_1]'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'cmap4_0_3'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'cmap4_3_1'}, {'id': '173', 'type': 'if_statement', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'nonBMP'}, {'id': '175', 'type': 'block', 'children': ['176', '184', '191', '198', '204', '210', '216', '222', '229', '235', '241', '247', '253']}; {'id': '176', 'type': 'import_from_statement', 'children': ['177', '182']}, {'id': '177', 'type': 'dotted_name', 'children': ['178', '179', '180', '181']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'fontTools'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'ttLib'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'tables'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': '_c_m_a_p'}; {'id': '182', 'type': 'dotted_name', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'cmap_format_12'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'nonBMP'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'mapping'}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'cmap12_0_4'}; {'id': '194', 'type': 'call', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'cmap_format_12'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'integer', 'children': [], 'value': '12'}; {'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': 'cmap12_0_4'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'platformID'}, {'id': '203', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'assignment', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'cmap12_0_4'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'platEncID'}, {'id': '209', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'cmap12_0_4'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'language'}, {'id': '215', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'cmap12_0_4'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'cmap'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'nonBMP'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'cmap12_3_10'}, {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'cmap_format_12'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'integer', 'children': [], 'value': '12'}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '234']}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'cmap12_3_10'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'platformID'}; {'id': '234', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'cmap12_3_10'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'platEncID'}; {'id': '240', 'type': 'integer', 'children': [], 'value': '10'}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '246']}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'cmap12_3_10'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'language'}; {'id': '246', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'assignment', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'cmap12_3_10'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'nonBMP'}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '258']}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'cmap'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'tables'}; {'id': '258', 'type': 'list', 'children': ['259', '260', '261', '262'], 'value': '[cmap4_0_3, cmap4_3_1, cmap12_0_4, cmap12_3_10]'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'cmap4_0_3'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'cmap4_3_1'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'cmap12_0_4'} | def setupTable_cmap(self):
if "cmap" not in self.tables:
return
from fontTools.ttLib.tables._c_m_a_p import cmap_format_4
nonBMP = dict((k,v) for k,v in self.unicodeToGlyphNameMapping.items() if k > 65535)
if nonBMP:
mapping = dict((k,v) for k,v in self.unicodeToGlyphNameMapping.items() if k <= 65535)
else:
mapping = dict(self.unicodeToGlyphNameMapping)
cmap4_0_3 = cmap_format_4(4)
cmap4_0_3.platformID = 0
cmap4_0_3.platEncID = 3
cmap4_0_3.language = 0
cmap4_0_3.cmap = mapping
cmap4_3_1 = cmap_format_4(4)
cmap4_3_1.platformID = 3
cmap4_3_1.platEncID = 1
cmap4_3_1.language = 0
cmap4_3_1.cmap = mapping
self.otf["cmap"] = cmap = newTable("cmap")
cmap.tableVersion = 0
cmap.tables = [cmap4_0_3, cmap4_3_1]
if nonBMP:
from fontTools.ttLib.tables._c_m_a_p import cmap_format_12
nonBMP.update(mapping)
cmap12_0_4 = cmap_format_12(12)
cmap12_0_4.platformID = 0
cmap12_0_4.platEncID = 4
cmap12_0_4.language = 0
cmap12_0_4.cmap = nonBMP
cmap12_3_10 = cmap_format_12(12)
cmap12_3_10.platformID = 3
cmap12_3_10.platEncID = 10
cmap12_3_10.language = 0
cmap12_3_10.cmap = nonBMP
cmap.tables = [cmap4_0_3, cmap4_3_1, cmap12_0_4, cmap12_3_10] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_setupTable_hhea_or_vhea'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '30', '43', '58', '64', '81', '91', '110', '144', '170', '174', '178', '182', '186', '294', '313', '332', '351', '370', '390', '403', '409']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '13']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'not'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'tables'}, {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'return_statement', 'children': []}, {'id': '15', 'type': 'if_statement', 'children': ['16', '19', '24']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': '=='}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '18', 'type': 'string', 'children': [], 'value': '"hhea"'}, {'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': 'isHhea'}, {'id': '23', 'type': 'True', 'children': []}; {'id': '24', 'type': 'else_clause', 'children': ['25']}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'isHhea'}, {'id': '29', 'type': 'False', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '37']}; {'id': '32', 'type': 'subscript', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'otf'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'newTable'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'mtxTable'}; {'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': 'otf'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'binary_operator', 'children': ['54', '57'], 'value': '+'}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'string', 'children': [], 'value': '"mtx"'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'font'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'ufo'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '66', '73']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'isHhea'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'tableVersion'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0x00010000'}, {'id': '73', 'type': 'else_clause', 'children': ['74']}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'tableVersion'}; {'id': '80', 'type': 'integer', 'children': [], 'value': '0x00011000'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'commonPrefix'}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '%'}, {'id': '85', 'type': 'string', 'children': [], 'value': '"openType%s"'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '90', 'type': 'argument_list', 'children': []}, {'id': '91', 'type': 'if_statement', 'children': ['92', '93', '98']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'isHhea'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'metricsPrefix'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'commonPrefix'}; {'id': '98', 'type': 'else_clause', 'children': ['99']}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'metricsPrefix'}, {'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '%'}; {'id': '104', 'type': 'string', 'children': [], 'value': '"openType%sVertTypo"'}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'title'}, {'id': '109', 'type': 'argument_list', 'children': []}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'metricsDict'}, {'id': '113', 'type': 'dictionary', 'children': ['114', '119', '124', '129', '134', '139']}; {'id': '114', 'type': 'pair', 'children': ['115', '116']}, {'id': '115', 'type': 'string', 'children': [], 'value': '"ascent"'}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '%'}, {'id': '117', 'type': 'string', 'children': [], 'value': '"%sAscender"'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'metricsPrefix'}, {'id': '119', 'type': 'pair', 'children': ['120', '121']}; {'id': '120', 'type': 'string', 'children': [], 'value': '"descent"'}, {'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '%'}; {'id': '122', 'type': 'string', 'children': [], 'value': '"%sDescender"'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'metricsPrefix'}; {'id': '124', 'type': 'pair', 'children': ['125', '126']}, {'id': '125', 'type': 'string', 'children': [], 'value': '"lineGap"'}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '%'}, {'id': '127', 'type': 'string', 'children': [], 'value': '"%sLineGap"'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'metricsPrefix'}, {'id': '129', 'type': 'pair', 'children': ['130', '131']}; {'id': '130', 'type': 'string', 'children': [], 'value': '"caretSlopeRise"'}, {'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '%'}; {'id': '132', 'type': 'string', 'children': [], 'value': '"%sCaretSlopeRise"'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'commonPrefix'}; {'id': '134', 'type': 'pair', 'children': ['135', '136']}, {'id': '135', 'type': 'string', 'children': [], 'value': '"caretSlopeRun"'}; {'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '%'}, {'id': '137', 'type': 'string', 'children': [], 'value': '"%sCaretSlopeRun"'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'commonPrefix'}, {'id': '139', 'type': 'pair', 'children': ['140', '141']}; {'id': '140', 'type': 'string', 'children': [], 'value': '"caretOffset"'}, {'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '%'}; {'id': '142', 'type': 'string', 'children': [], 'value': '"%sCaretOffset"'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'commonPrefix'}; {'id': '144', 'type': 'for_statement', 'children': ['145', '148', '153']}, {'id': '145', 'type': 'pattern_list', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'otfName'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ufoName'}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'metricsDict'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '152', 'type': 'argument_list', 'children': []}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '157', 'type': 'argument_list', 'children': ['158', '159', '160']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'otfName'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'otRound'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'getAttrWithFallback'}, {'id': '165', 'type': 'argument_list', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'font'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ufoName'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}, {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'advances'}, {'id': '173', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'firstSideBearings'}, {'id': '177', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'secondSideBearings'}, {'id': '181', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'extents'}, {'id': '185', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '186', 'type': 'if_statement', 'children': ['187', '190']}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'is'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'mtxTable'}, {'id': '189', 'type': 'None', 'children': []}; {'id': '190', 'type': 'block', 'children': ['191']}, {'id': '191', 'type': 'for_statement', 'children': ['192', '193', '196']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'glyphName'}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'allGlyphs'}; {'id': '196', 'type': 'block', 'children': ['197', '205', '212', '220', '226', '265', '273', '280', '287']}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '202']}, {'id': '199', 'type': 'pattern_list', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'advance'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'firstSideBearing'}; {'id': '202', 'type': 'subscript', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'mtxTable'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'glyphName'}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'call', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'advances'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'advance'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'bounds'}, {'id': '215', 'type': 'subscript', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'glyphBoundingBoxes'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'glyphName'}; {'id': '220', 'type': 'if_statement', 'children': ['221', '224']}, {'id': '221', 'type': 'comparison_operator', 'children': ['222', '223'], 'value': 'is'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'bounds'}, {'id': '223', 'type': 'None', 'children': []}; {'id': '224', 'type': 'block', 'children': ['225']}, {'id': '225', 'type': 'continue_statement', 'children': []}; {'id': '226', 'type': 'if_statement', 'children': ['227', '228', '246']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'isHhea'}; {'id': '228', 'type': 'block', 'children': ['229', '240']}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'boundsAdvance'}; {'id': '232', 'type': 'parenthesized_expression', 'children': ['233'], 'value': '()'}, {'id': '233', 'type': 'binary_operator', 'children': ['234', '237'], 'value': '-'}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'bounds'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'xMax'}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'bounds'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'xMin'}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}, {'id': '241', 'type': 'assignment', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'extent'}, {'id': '243', 'type': 'binary_operator', 'children': ['244', '245'], 'value': '+'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'firstSideBearing'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'boundsAdvance'}; {'id': '246', 'type': 'else_clause', 'children': ['247']}, {'id': '247', 'type': 'block', 'children': ['248', '259']}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'assignment', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'boundsAdvance'}, {'id': '251', 'type': 'parenthesized_expression', 'children': ['252'], 'value': '()'}; {'id': '252', 'type': 'binary_operator', 'children': ['253', '256'], 'value': '-'}, {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'bounds'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'yMax'}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'bounds'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'yMin'}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'assignment', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'extent'}; {'id': '262', 'type': 'binary_operator', 'children': ['263', '264'], 'value': '+'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'firstSideBearing'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'boundsAdvance'}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'secondSideBearing'}; {'id': '268', 'type': 'binary_operator', 'children': ['269', '272'], 'value': '-'}, {'id': '269', 'type': 'binary_operator', 'children': ['270', '271'], 'value': '-'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'advance'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'firstSideBearing'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'boundsAdvance'}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'call', 'children': ['275', '278']}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'firstSideBearings'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'firstSideBearing'}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'call', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'secondSideBearings'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'secondSideBearing'}, {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'call', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'extents'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'extent'}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}, {'id': '295', 'type': 'call', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '297', 'type': 'argument_list', 'children': ['298', '299', '306']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '299', 'type': 'binary_operator', 'children': ['300', '301'], 'value': '%'}; {'id': '300', 'type': 'string', 'children': [], 'value': '"advance%sMax"'}, {'id': '301', 'type': 'parenthesized_expression', 'children': ['302'], 'value': '()'}; {'id': '302', 'type': 'conditional_expression', 'children': ['303', '304', '305'], 'value': 'if'}, {'id': '303', 'type': 'string', 'children': [], 'value': '"Width"'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'isHhea'}, {'id': '305', 'type': 'string', 'children': [], 'value': '"Height"'}; {'id': '306', 'type': 'conditional_expression', 'children': ['307', '311', '312'], 'value': 'if'}, {'id': '307', 'type': 'call', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'advances'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'advances'}; {'id': '312', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'call', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '316', 'type': 'argument_list', 'children': ['317', '318', '325']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '318', 'type': 'binary_operator', 'children': ['319', '320'], 'value': '%'}, {'id': '319', 'type': 'string', 'children': [], 'value': '"min%sSideBearing"'}; {'id': '320', 'type': 'parenthesized_expression', 'children': ['321'], 'value': '()'}, {'id': '321', 'type': 'conditional_expression', 'children': ['322', '323', '324'], 'value': 'if'}; {'id': '322', 'type': 'string', 'children': [], 'value': '"Left"'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'isHhea'}; {'id': '324', 'type': 'string', 'children': [], 'value': '"Top"'}, {'id': '325', 'type': 'conditional_expression', 'children': ['326', '330', '331'], 'value': 'if'}; {'id': '326', 'type': 'call', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '328', 'type': 'argument_list', 'children': ['329']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'firstSideBearings'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'firstSideBearings'}, {'id': '331', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}, {'id': '333', 'type': 'call', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '335', 'type': 'argument_list', 'children': ['336', '337', '344']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '337', 'type': 'binary_operator', 'children': ['338', '339'], 'value': '%'}; {'id': '338', 'type': 'string', 'children': [], 'value': '"min%sSideBearing"'}, {'id': '339', 'type': 'parenthesized_expression', 'children': ['340'], 'value': '()'}; {'id': '340', 'type': 'conditional_expression', 'children': ['341', '342', '343'], 'value': 'if'}, {'id': '341', 'type': 'string', 'children': [], 'value': '"Right"'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'isHhea'}, {'id': '343', 'type': 'string', 'children': [], 'value': '"Bottom"'}; {'id': '344', 'type': 'conditional_expression', 'children': ['345', '349', '350'], 'value': 'if'}, {'id': '345', 'type': 'call', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'min'}, {'id': '347', 'type': 'argument_list', 'children': ['348']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'secondSideBearings'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'secondSideBearings'}; {'id': '350', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '351', 'type': 'expression_statement', 'children': ['352']}; {'id': '352', 'type': 'call', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '354', 'type': 'argument_list', 'children': ['355', '356', '363']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '356', 'type': 'binary_operator', 'children': ['357', '358'], 'value': '%'}, {'id': '357', 'type': 'string', 'children': [], 'value': '"%sMaxExtent"'}; {'id': '358', 'type': 'parenthesized_expression', 'children': ['359'], 'value': '()'}, {'id': '359', 'type': 'conditional_expression', 'children': ['360', '361', '362'], 'value': 'if'}; {'id': '360', 'type': 'string', 'children': [], 'value': '"x"'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'isHhea'}; {'id': '362', 'type': 'string', 'children': [], 'value': '"y"'}, {'id': '363', 'type': 'conditional_expression', 'children': ['364', '368', '369'], 'value': 'if'}; {'id': '364', 'type': 'call', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '366', 'type': 'argument_list', 'children': ['367']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'extents'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'extents'}, {'id': '369', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '370', 'type': 'if_statement', 'children': ['371', '372', '380']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'isHhea'}; {'id': '372', 'type': 'block', 'children': ['373']}, {'id': '373', 'type': 'expression_statement', 'children': ['374']}; {'id': '374', 'type': 'assignment', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'reserved'}; {'id': '376', 'type': 'call', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '378', 'type': 'argument_list', 'children': ['379']}, {'id': '379', 'type': 'integer', 'children': [], 'value': '4'}; {'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': 'reserved'}, {'id': '385', 'type': 'call', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '387', 'type': 'argument_list', 'children': ['388', '389']}; {'id': '388', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '389', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '390', 'type': 'for_statement', 'children': ['391', '392', '393']}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'reserved'}, {'id': '393', 'type': 'block', 'children': ['394']}; {'id': '394', 'type': 'expression_statement', 'children': ['395']}, {'id': '395', 'type': 'call', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '397', 'type': 'argument_list', 'children': ['398', '399', '402']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '399', 'type': 'binary_operator', 'children': ['400', '401'], 'value': '%'}; {'id': '400', 'type': 'string', 'children': [], 'value': '"reserved%i"'}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '402', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '403', 'type': 'expression_statement', 'children': ['404']}; {'id': '404', 'type': 'assignment', 'children': ['405', '408']}, {'id': '405', 'type': 'attribute', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'table'}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'metricDataFormat'}; {'id': '408', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '409', 'type': 'expression_statement', 'children': ['410']}; {'id': '410', 'type': 'call', 'children': ['411', '412']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '412', 'type': 'argument_list', 'children': ['413', '414', '421']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'table'}; {'id': '414', 'type': 'binary_operator', 'children': ['415', '416'], 'value': '%'}, {'id': '415', 'type': 'string', 'children': [], 'value': '"numberOf%sMetrics"'}; {'id': '416', 'type': 'parenthesized_expression', 'children': ['417'], 'value': '()'}, {'id': '417', 'type': 'conditional_expression', 'children': ['418', '419', '420'], 'value': 'if'}; {'id': '418', 'type': 'string', 'children': [], 'value': '"H"'}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'isHhea'}; {'id': '420', 'type': 'string', 'children': [], 'value': '"V"'}, {'id': '421', 'type': 'call', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '423', 'type': 'argument_list', 'children': ['424']}; {'id': '424', 'type': 'attribute', 'children': ['425', '426']}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'self'} | def _setupTable_hhea_or_vhea(self, tag):
if tag not in self.tables:
return
if tag == "hhea":
isHhea = True
else:
isHhea = False
self.otf[tag] = table = newTable(tag)
mtxTable = self.otf.get(tag[0] + "mtx")
font = self.ufo
if isHhea:
table.tableVersion = 0x00010000
else:
table.tableVersion = 0x00011000
commonPrefix = "openType%s" % tag.title()
if isHhea:
metricsPrefix = commonPrefix
else:
metricsPrefix = "openType%sVertTypo" % tag.title()
metricsDict = {
"ascent": "%sAscender" % metricsPrefix,
"descent": "%sDescender" % metricsPrefix,
"lineGap": "%sLineGap" % metricsPrefix,
"caretSlopeRise": "%sCaretSlopeRise" % commonPrefix,
"caretSlopeRun": "%sCaretSlopeRun" % commonPrefix,
"caretOffset": "%sCaretOffset" % commonPrefix,
}
for otfName, ufoName in metricsDict.items():
setattr(table, otfName,
otRound(getAttrWithFallback(font.info, ufoName)))
advances = []
firstSideBearings = []
secondSideBearings = []
extents = []
if mtxTable is not None:
for glyphName in self.allGlyphs:
advance, firstSideBearing = mtxTable[glyphName]
advances.append(advance)
bounds = self.glyphBoundingBoxes[glyphName]
if bounds is None:
continue
if isHhea:
boundsAdvance = (bounds.xMax - bounds.xMin)
extent = firstSideBearing + boundsAdvance
else:
boundsAdvance = (bounds.yMax - bounds.yMin)
extent = firstSideBearing + boundsAdvance
secondSideBearing = advance - firstSideBearing - boundsAdvance
firstSideBearings.append(firstSideBearing)
secondSideBearings.append(secondSideBearing)
extents.append(extent)
setattr(table,
"advance%sMax" % ("Width" if isHhea else "Height"),
max(advances) if advances else 0)
setattr(table,
"min%sSideBearing" % ("Left" if isHhea else "Top"),
min(firstSideBearings) if firstSideBearings else 0)
setattr(table,
"min%sSideBearing" % ("Right" if isHhea else "Bottom"),
min(secondSideBearings) if secondSideBearings else 0)
setattr(table,
"%sMaxExtent" % ("x" if isHhea else "y"),
max(extents) if extents else 0)
if isHhea:
reserved = range(4)
else:
reserved = range(1, 5)
for i in reserved:
setattr(table, "reserved%i" % i, 0)
table.metricDataFormat = 0
setattr(table,
"numberOf%sMetrics" % ("H" if isHhea else "V"),
len(self.allGlyphs)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dir'}, {'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': 'methods'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'showall'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '15', '51', '56', '63', '65']}; {'id': '12', 'type': 'import_statement', 'children': ['13']}, {'id': '13', 'type': 'dotted_name', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'inspect'}, {'id': '15', 'type': 'for_statement', 'children': ['16', '19', '29']}; {'id': '16', 'type': 'pattern_list', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30', '39']}; {'id': '30', 'type': 'if_statement', 'children': ['31', '37']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': '"_"'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'continue_statement', 'children': []}, {'id': '39', 'type': 'print_statement', 'children': ['40', '49', '50']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'makeminlength'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '46']}, {'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '+'}; {'id': '44', 'type': 'string', 'children': [], 'value': '"."'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'being'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'linelen'}, {'id': '49', 'type': 'string', 'children': [], 'value': '"\\t"'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '51', 'type': 'if_statement', 'children': ['52', '54']}; {'id': '52', 'type': 'not_operator', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'methods'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'return_statement', 'children': []}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'entmethods'}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'dir'}, {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'entity'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '65', 'type': 'for_statement', 'children': ['66', '67', '101']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '67', 'type': 'list_comprehension', 'children': ['68', '69', '75']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '69', 'type': 'for_in_clause', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'dir'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'if_clause', 'children': ['76']}; {'id': '76', 'type': 'boolean_operator', 'children': ['77', '94'], 'value': 'and'}, {'id': '77', 'type': 'parenthesized_expression', 'children': ['78'], 'value': '()'}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '86'], 'value': 'in'}, {'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '+'}; {'id': '80', 'type': 'string', 'children': [], 'value': '"bound method "'}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'classname'}, {'id': '85', 'type': 'argument_list', 'children': []}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '94', 'type': 'not_operator', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'string', 'children': [], 'value': '"_"'}, {'id': '101', 'type': 'block', 'children': ['102', '113', '121', '127', '135', '142', '173', '191']}; {'id': '102', 'type': 'if_statement', 'children': ['103', '111']}, {'id': '103', 'type': 'boolean_operator', 'children': ['104', '107'], 'value': 'and'}; {'id': '104', 'type': 'parenthesized_expression', 'children': ['105'], 'value': '()'}, {'id': '105', 'type': 'not_operator', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'showall'}, {'id': '107', 'type': 'parenthesized_expression', 'children': ['108'], 'value': '()'}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'in'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'entmethods'}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'continue_statement', 'children': []}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'doc'}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': '__doc__'}, {'id': '127', 'type': 'if_statement', 'children': ['128', '130']}; {'id': '128', 'type': 'not_operator', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'doc'}; {'id': '130', 'type': 'block', 'children': ['131']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'doc'}; {'id': '134', 'type': 'string', 'children': [], 'value': '""'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'describe_func'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '142', 'type': 'if_statement', 'children': ['143', '145', '150']}, {'id': '143', 'type': 'not_operator', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'y'}, {'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': 'y'}, {'id': '149', 'type': 'string', 'children': [], 'value': '""'}; {'id': '150', 'type': 'else_clause', 'children': ['151']}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'string', 'children': [], 'value': '", "'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '159', 'type': 'generator_expression', 'children': ['160', '168']}; {'id': '160', 'type': 'binary_operator', 'children': ['161', '164'], 'value': '+'}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '+'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '163', 'type': 'string', 'children': [], 'value': '"="'}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '168', 'type': 'for_in_clause', 'children': ['169', '172']}, {'id': '169', 'type': 'tuple_pattern', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '173', 'type': 'print_statement', 'children': ['174', '189', '190']}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'makeminlength'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '186']}, {'id': '177', 'type': 'binary_operator', 'children': ['178', '185'], 'value': '+'}; {'id': '178', 'type': 'binary_operator', 'children': ['179', '184'], 'value': '+'}, {'id': '179', 'type': 'binary_operator', 'children': ['180', '183'], 'value': '+'}; {'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '+'}, {'id': '181', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '183', 'type': 'string', 'children': [], 'value': '"("'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'y'}, {'id': '185', 'type': 'string', 'children': [], 'value': '")"'}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'being'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'linelen'}, {'id': '189', 'type': 'string', 'children': [], 'value': '"\\t"'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'doc'}, {'id': '191', 'type': 'if_statement', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'showall'}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'print'} | def dir(self,methods=True,showall=True):
import inspect
for k,v in sorted(self.__dict__.items()):
if k.startswith("_"): continue
print makeminlength("."+k,being.linelen),"\t",v
if not methods:
return
entmethods=dir(entity)
print
for x in [x for x in dir(self) if ("bound method "+self.classname() in str(getattr(self,x))) and not x.startswith("_")]:
if (not showall) and (x in entmethods): continue
attr=getattr(self,x)
doc = attr.__doc__
if not doc:
doc=""
y=describe_func(attr)
if not y:
y=""
else:
y=", ".join(a+"="+str(b) for (a,b) in y)
print makeminlength("."+x+"("+y+")",being.linelen),"\t", doc
if showall: print |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tree'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'prefix_inherited'}; {'id': '10', 'type': 'string', 'children': [], 'value': '""'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'nofeatsplease'}, {'id': '13', 'type': 'list', 'children': ['14'], 'value': "['Phoneme']"}; {'id': '14', 'type': 'string', 'children': [], 'value': "'Phoneme'"}, {'id': '15', 'type': 'block', 'children': ['16', '20', '24', '332']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '19', 'type': 'string', 'children': [], 'value': '""'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'numchild'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '29']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '29', 'type': 'block', 'children': ['30', '47', '51', '59', '86', '111', '115', '119', '131', '135', '139', '156', '169', '186', '316', '320']}; {'id': '30', 'type': 'if_statement', 'children': ['31', '40']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '36'], 'value': '=='}; {'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': 'child'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'list', 'children': [], 'value': '[]'}; {'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': 'child'}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '46', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'augmented_assignment', 'children': ['49', '50'], 'value': '+='}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'numchild'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'id': '59', 'type': 'if_statement', 'children': ['60', '63', '68', '77']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '=='}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '62', 'type': 'string', 'children': [], 'value': '"Word"'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'augmented_assignment', 'children': ['66', '67'], 'value': '+='}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '67', 'type': 'string', 'children': [], 'value': '"\\n\\n"'}; {'id': '68', 'type': 'elif_clause', 'children': ['69', '72']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '=='}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'classname'}, {'id': '71', 'type': 'string', 'children': [], 'value': '"Line"'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'augmented_assignment', 'children': ['75', '76'], 'value': '+='}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '76', 'type': 'string', 'children': [], 'value': '"\\n\\n\\n"'}, {'id': '77', 'type': 'elif_clause', 'children': ['78', '81']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': '=='}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '80', 'type': 'string', 'children': [], 'value': '"Stanza"'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'augmented_assignment', 'children': ['84', '85'], 'value': '+='}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '85', 'type': 'string', 'children': [], 'value': '"\\n\\n\\n\\n"'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '90']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '!='}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'offset'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '90', 'type': 'block', 'children': ['91', '95', '107']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'augmented_assignment', 'children': ['93', '94'], 'value': '+='}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '94', 'type': 'string', 'children': [], 'value': '"\\n"'}, {'id': '95', 'type': 'for_statement', 'children': ['96', '97', '102']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'augmented_assignment', 'children': ['105', '106'], 'value': '+='}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '106', 'type': 'string', 'children': [], 'value': '" "'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'augmented_assignment', 'children': ['109', '110'], 'value': '+='}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '110', 'type': 'string', 'children': [], 'value': '"|"'}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'augmented_assignment', 'children': ['113', '114'], 'value': '+='}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '114', 'type': 'string', 'children': [], 'value': '"\\n"'}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'newline'}; {'id': '118', 'type': 'string', 'children': [], 'value': '""'}, {'id': '119', 'type': 'for_statement', 'children': ['120', '121', '126']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'augmented_assignment', 'children': ['129', '130'], 'value': '+='}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'newline'}; {'id': '130', 'type': 'string', 'children': [], 'value': '" "'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'augmented_assignment', 'children': ['133', '134'], 'value': '+='}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'newline'}; {'id': '134', 'type': 'string', 'children': [], 'value': '"|"'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'cname'}; {'id': '138', 'type': 'string', 'children': [], 'value': '""'}, {'id': '139', 'type': 'for_statement', 'children': ['140', '141', '142']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'letter'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'if_statement', 'children': ['144', '151']}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': '=='}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'letter'}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'letter'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '150', 'type': 'argument_list', 'children': []}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'augmented_assignment', 'children': ['154', '155'], 'value': '+='}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'cname'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'letter'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '159', 'type': 'binary_operator', 'children': ['160', '168'], 'value': '+'}; {'id': '160', 'type': 'binary_operator', 'children': ['161', '164'], 'value': '+'}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '+'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'prefix_inherited'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'cname'}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'numchild'}; {'id': '168', 'type': 'string', 'children': [], 'value': '"."'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'augmented_assignment', 'children': ['171', '172'], 'value': '+='}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'newline'}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '185'], 'value': '+'}, {'id': '173', 'type': 'binary_operator', 'children': ['174', '184'], 'value': '+'}; {'id': '174', 'type': 'binary_operator', 'children': ['175', '183'], 'value': '+'}, {'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '+'}; {'id': '176', 'type': 'string', 'children': [], 'value': '"-----| ("'}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'prefix'}, {'id': '179', 'type': 'slice', 'children': ['180', '181']}; {'id': '180', 'type': 'colon', 'children': []}, {'id': '181', 'type': 'unary_operator', 'children': ['182'], 'value': '-'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '183', 'type': 'string', 'children': [], 'value': '") <"'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'classname'}, {'id': '185', 'type': 'string', 'children': [], 'value': '">"'}; {'id': '186', 'type': 'if_statement', 'children': ['187', '192', '197']}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'isBroken'}, {'id': '191', 'type': 'argument_list', 'children': []}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'augmented_assignment', 'children': ['195', '196'], 'value': '+='}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'newline'}; {'id': '196', 'type': 'string', 'children': [], 'value': '"<<broken>>"'}, {'id': '197', 'type': 'else_clause', 'children': ['198']}; {'id': '198', 'type': 'block', 'children': ['199', '208', '244']}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'u2s'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '208', 'type': 'if_statement', 'children': ['209', '214', '231']}, {'id': '209', 'type': 'parenthesized_expression', 'children': ['210'], 'value': '()'}; {'id': '210', 'type': 'not_operator', 'children': ['211']}, {'id': '211', 'type': 'comparison_operator', 'children': ['212', '213'], 'value': 'in'}; {'id': '212', 'type': 'string', 'children': [], 'value': '"<"'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '214', 'type': 'block', 'children': ['215', '223']}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'newline'}; {'id': '218', 'type': 'call', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'makeminlength'}; {'id': '220', 'type': 'argument_list', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'newline'}; {'id': '222', 'type': 'integer', 'children': [], 'value': '99'}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'augmented_assignment', 'children': ['225', '226'], 'value': '+='}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'newline'}; {'id': '226', 'type': 'binary_operator', 'children': ['227', '230'], 'value': '+'}, {'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '+'}; {'id': '228', 'type': 'string', 'children': [], 'value': '"["'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '230', 'type': 'string', 'children': [], 'value': '"]"'}, {'id': '231', 'type': 'elif_clause', 'children': ['232', '237']}; {'id': '232', 'type': 'comparison_operator', 'children': ['233', '236'], 'value': '!='}, {'id': '233', 'type': 'subscript', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'string'}, {'id': '235', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '236', 'type': 'string', 'children': [], 'value': '"<"'}, {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'augmented_assignment', 'children': ['240', '241'], 'value': '+='}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'newline'}, {'id': '241', 'type': 'binary_operator', 'children': ['242', '243'], 'value': '+'}; {'id': '242', 'type': 'string', 'children': [], 'value': '"\\t"'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '244', 'type': 'if_statement', 'children': ['245', '251']}, {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'feats'}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'if_statement', 'children': ['253', '262']}, {'id': '253', 'type': 'parenthesized_expression', 'children': ['254'], 'value': '()'}; {'id': '254', 'type': 'not_operator', 'children': ['255']}, {'id': '255', 'type': 'comparison_operator', 'children': ['256', '261'], 'value': 'in'}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'classname'}; {'id': '260', 'type': 'argument_list', 'children': []}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'nofeatsplease'}; {'id': '262', 'type': 'block', 'children': ['263']}, {'id': '263', 'type': 'for_statement', 'children': ['264', '267', '277']}; {'id': '264', 'type': 'pattern_list', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '267', 'type': 'call', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'call', 'children': ['271', '276']}, {'id': '271', 'type': 'attribute', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'feats'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '276', 'type': 'argument_list', 'children': []}, {'id': '277', 'type': 'block', 'children': ['278', '284', '288', '302', '306']}; {'id': '278', 'type': 'if_statement', 'children': ['279', '282']}, {'id': '279', 'type': 'comparison_operator', 'children': ['280', '281'], 'value': '=='}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '281', 'type': 'None', 'children': []}; {'id': '282', 'type': 'block', 'children': ['283']}, {'id': '283', 'type': 'continue_statement', 'children': []}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'augmented_assignment', 'children': ['286', '287'], 'value': '+='}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'newline'}, {'id': '287', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '288', 'type': 'for_statement', 'children': ['289', '290', '297']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '290', 'type': 'call', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '292', 'type': 'argument_list', 'children': ['293', '294']}, {'id': '293', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '294', 'type': 'binary_operator', 'children': ['295', '296'], 'value': '+'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '296', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '297', 'type': 'block', 'children': ['298']}; {'id': '298', 'type': 'expression_statement', 'children': ['299']}, {'id': '299', 'type': 'augmented_assignment', 'children': ['300', '301'], 'value': '+='}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'newline'}, {'id': '301', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'augmented_assignment', 'children': ['304', '305'], 'value': '+='}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'newline'}, {'id': '305', 'type': 'string', 'children': [], 'value': '"| "'}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'augmented_assignment', 'children': ['308', '309'], 'value': '+='}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'newline'}, {'id': '309', 'type': 'call', 'children': ['310', '313']}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'showFeat'}, {'id': '313', 'type': 'argument_list', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'augmented_assignment', 'children': ['318', '319'], 'value': '+='}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'newline'}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'augmented_assignment', 'children': ['322', '323'], 'value': '+='}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '323', 'type': 'call', 'children': ['324', '327']}; {'id': '324', 'type': 'attribute', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '327', 'type': 'argument_list', 'children': ['328', '331']}; {'id': '328', 'type': 'binary_operator', 'children': ['329', '330'], 'value': '+'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '330', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '332', 'type': 'return_statement', 'children': ['333']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'tree'} | def tree(self,offset=0,prefix_inherited="",nofeatsplease=['Phoneme']):
tree = ""
numchild=0
for child in self.children:
if type(child)==type([]):
child=child[0]
numchild+=1
classname=child.classname()
if classname=="Word":
tree+="\n\n"
elif classname=="Line":
tree+="\n\n\n"
elif classname=="Stanza":
tree+="\n\n\n\n"
if offset!=0:
tree+="\n"
for i in range(0,offset):
tree+=" "
tree+="|"
tree+="\n"
newline=""
for i in range(0,offset):
newline+=" "
newline+="|"
cname=""
for letter in classname:
if letter==letter.upper():
cname+=letter
prefix=prefix_inherited+cname+str(numchild) + "."
newline+="-----| ("+prefix[:-1]+") <"+classname+">"
if child.isBroken():
newline+="<<broken>>"
else:
string=self.u2s(child)
if (not "<" in string):
newline=makeminlength(newline,99)
newline+="["+string+"]"
elif string[0]!="<":
newline+="\t"+string
if len(child.feats):
if (not child.classname() in nofeatsplease):
for k,v in sorted(child.feats.items()):
if v==None:
continue
newline+="\n"
for i in range(0,offset+1):
newline+=" "
newline+="| "
newline+=self.showFeat(k,v)
tree+=newline
tree+=child.tree(offset+1,prefix)
return tree |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'stats_positions'}, {'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': 'meter'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'all_parses'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '38', '42', '130', '293', '305', '324', '360', '371']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'parses'}, {'id': '15', 'type': 'conditional_expression', 'children': ['16', '24', '25'], 'value': 'if'}; {'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': 'allParses'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'keyword_argument', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'meter'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'meter'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'all_parses'}, {'id': '25', 'type': 'list_comprehension', 'children': ['26', '28']}; {'id': '26', 'type': 'list', 'children': ['27'], 'value': '[parse]'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'bestParses'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'meter'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'meter'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'dx'}, {'id': '41', 'type': 'dictionary', 'children': []}; {'id': '42', 'type': 'for_statement', 'children': ['43', '44', '45']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'parselist'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'parses'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'for_statement', 'children': ['47', '48', '49']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'parselist'}, {'id': '49', 'type': 'block', 'children': ['50', '55', '59']}; {'id': '50', 'type': 'if_statement', 'children': ['51', '53']}, {'id': '51', 'type': 'not_operator', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'continue_statement', 'children': []}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'slot_i'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '59', 'type': 'for_statement', 'children': ['60', '61', '64']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'positions'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'for_statement', 'children': ['66', '67', '70']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'slot'}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'slots'}; {'id': '70', 'type': 'block', 'children': ['71', '75', '88']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'augmented_assignment', 'children': ['73', '74'], 'value': '+='}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'slot_i'}; {'id': '74', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'feat_dicts'}; {'id': '78', 'type': 'list', 'children': ['79', '82', '85'], 'value': '[slot.feats, pos.constraintScores, pos.feats]'}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'slot'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'feats'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'pos'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'constraintScores'}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'feats'}; {'id': '88', 'type': 'for_statement', 'children': ['89', '90', '91']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'feat_dict'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'feat_dicts'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'for_statement', 'children': ['93', '96', '101']}, {'id': '93', 'type': 'pattern_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'feat_dict'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '100', 'type': 'argument_list', 'children': []}, {'id': '101', 'type': 'block', 'children': ['102', '111', '123']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'dk'}, {'id': '105', 'type': 'tuple', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'slot_i'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '111', 'type': 'if_statement', 'children': ['112', '116']}; {'id': '112', 'type': 'not_operator', 'children': ['113']}, {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'in'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'dk'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'dx'}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '122']}, {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'dx'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'dk'}; {'id': '122', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'augmented_assignment', 'children': ['125', '128'], 'value': '+='}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'dx'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'dk'}; {'id': '128', 'type': 'list', 'children': ['129'], 'value': '[v]'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '130', 'type': 'function_definition', 'children': ['131', '132', '133']}, {'id': '131', 'type': 'function_name', 'children': [], 'value': '_writegen'}; {'id': '132', 'type': 'parameters', 'children': []}, {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'for_statement', 'children': ['135', '140', '148']}, {'id': '135', 'type': 'tuple_pattern', 'children': ['136', '139']}; {'id': '136', 'type': 'tuple_pattern', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'slot_i'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'dx'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '147', 'type': 'argument_list', 'children': []}; {'id': '148', 'type': 'block', 'children': ['149', '153', '221', '226', '241', '248', '255', '279', '290']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'l2'}; {'id': '152', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '153', 'type': 'for_statement', 'children': ['154', '155', '156']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '156', 'type': 'block', 'children': ['157', '207', '216']}, {'id': '157', 'type': 'if_statement', 'children': ['158', '164', '172', '187', '198']}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '163'], 'value': '=='}, {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '164', 'type': 'block', 'children': ['165']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '168', 'type': 'conditional_expression', 'children': ['169', '170', '171'], 'value': 'if'}, {'id': '169', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '171', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '172', 'type': 'elif_clause', 'children': ['173', '182']}, {'id': '173', 'type': 'comparison_operator', 'children': ['174', '178'], 'value': '=='}; {'id': '174', 'type': 'call', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'None', 'children': []}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '187', 'type': 'elif_clause', 'children': ['188', '196']}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '193'], 'value': 'in'}, {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '193', 'type': 'list', 'children': ['194', '195'], 'value': '[str,unicode]'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'unicode'}; {'id': '196', 'type': 'block', 'children': ['197']}, {'id': '197', 'type': 'continue_statement', 'children': []}; {'id': '198', 'type': 'else_clause', 'children': ['199']}, {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'assignment', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '207', 'type': 'if_statement', 'children': ['208', '211']}; {'id': '208', 'type': 'comparison_operator', 'children': ['209', '210'], 'value': '>'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '210', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '211', 'type': 'block', 'children': ['212']}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '215', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'augmented_assignment', 'children': ['218', '219'], 'value': '+='}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'l2'}, {'id': '219', 'type': 'list', 'children': ['220'], 'value': '[x]'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '221', 'type': 'if_statement', 'children': ['222', '224']}; {'id': '222', 'type': 'not_operator', 'children': ['223']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'l2'}; {'id': '224', 'type': 'block', 'children': ['225']}, {'id': '225', 'type': 'continue_statement', 'children': []}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}, {'id': '227', 'type': 'assignment', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'avg'}, {'id': '229', 'type': 'binary_operator', 'children': ['230', '234'], 'value': '/'}; {'id': '230', 'type': 'call', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'l2'}; {'id': '234', 'type': 'call', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}, {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'l2'}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '244', 'type': 'call', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'l2'}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'assignment', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'chances'}, {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'l2'}, {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'odx'}; {'id': '258', 'type': 'dictionary', 'children': ['259', '262', '265', '268', '271', '274']}, {'id': '259', 'type': 'pair', 'children': ['260', '261']}; {'id': '260', 'type': 'string', 'children': [], 'value': "'slot_num'"}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'slot_i'}; {'id': '262', 'type': 'pair', 'children': ['263', '264']}, {'id': '263', 'type': 'string', 'children': [], 'value': "'statistic'"}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '265', 'type': 'pair', 'children': ['266', '267']}; {'id': '266', 'type': 'string', 'children': [], 'value': "'average'"}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'avg'}; {'id': '268', 'type': 'pair', 'children': ['269', '270']}, {'id': '269', 'type': 'string', 'children': [], 'value': "'count'"}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '271', 'type': 'pair', 'children': ['272', '273']}; {'id': '272', 'type': 'string', 'children': [], 'value': "'chances'"}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'chances'}; {'id': '274', 'type': 'pair', 'children': ['275', '276']}, {'id': '275', 'type': 'string', 'children': [], 'value': "'text'"}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '284']}, {'id': '281', 'type': 'subscript', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'odx'}, {'id': '283', 'type': 'string', 'children': [], 'value': "'header'"}; {'id': '284', 'type': 'list', 'children': ['285', '286', '287', '288', '289'], 'value': "['slot_num', 'statistic','count','chances','average']"}, {'id': '285', 'type': 'string', 'children': [], 'value': "'slot_num'"}; {'id': '286', 'type': 'string', 'children': [], 'value': "'statistic'"}, {'id': '287', 'type': 'string', 'children': [], 'value': "'count'"}; {'id': '288', 'type': 'string', 'children': [], 'value': "'chances'"}, {'id': '289', 'type': 'string', 'children': [], 'value': "'average'"}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'yield', 'children': ['292']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'odx'}, {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'assignment', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '296', 'type': 'call', 'children': ['297', '302']}, {'id': '297', 'type': 'attribute', 'children': ['298', '301']}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '302', 'type': 'argument_list', 'children': ['303', '304']}, {'id': '303', 'type': 'string', 'children': [], 'value': "'.txt'"}; {'id': '304', 'type': 'string', 'children': [], 'value': "''"}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'ofn'}; {'id': '308', 'type': 'call', 'children': ['309', '314']}, {'id': '309', 'type': 'attribute', 'children': ['310', '313']}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '314', 'type': 'argument_list', 'children': ['315', '318', '319', '320', '321']}, {'id': '315', 'type': 'attribute', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'dir_results'}; {'id': '318', 'type': 'string', 'children': [], 'value': "'stats'"}, {'id': '319', 'type': 'string', 'children': [], 'value': "'texts'"}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '321', 'type': 'binary_operator', 'children': ['322', '323'], 'value': '+'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '323', 'type': 'string', 'children': [], 'value': "'.positions.csv'"}; {'id': '324', 'type': 'if_statement', 'children': ['325', '343']}, {'id': '325', 'type': 'not_operator', 'children': ['326']}; {'id': '326', 'type': 'call', 'children': ['327', '332']}, {'id': '327', 'type': 'attribute', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '332', 'type': 'argument_list', 'children': ['333']}, {'id': '333', 'type': 'subscript', 'children': ['334', '342']}; {'id': '334', 'type': 'call', 'children': ['335', '340']}, {'id': '335', 'type': 'attribute', 'children': ['336', '339']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '340', 'type': 'argument_list', 'children': ['341']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'ofn'}; {'id': '342', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '343', 'type': 'block', 'children': ['344']}; {'id': '344', 'type': 'expression_statement', 'children': ['345']}, {'id': '345', 'type': 'call', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'makedirs'}, {'id': '349', 'type': 'argument_list', 'children': ['350']}; {'id': '350', 'type': 'subscript', 'children': ['351', '359']}, {'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': 'os'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '357', 'type': 'argument_list', 'children': ['358']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'ofn'}, {'id': '359', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '360', 'type': 'for_statement', 'children': ['361', '362', '367']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'dx'}; {'id': '362', 'type': 'call', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'writegengen'}; {'id': '364', 'type': 'argument_list', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'ofn'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': '_writegen'}, {'id': '367', 'type': 'block', 'children': ['368']}; {'id': '368', 'type': 'expression_statement', 'children': ['369']}, {'id': '369', 'type': 'yield', 'children': ['370']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'dx'}, {'id': '371', 'type': 'print_statement', 'children': ['372', '373']}; {'id': '372', 'type': 'string', 'children': [], 'value': "'>> saved:'"}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'ofn'} | def stats_positions(self,meter=None,all_parses=False):
parses = self.allParses(meter=meter) if all_parses else [[parse] for parse in self.bestParses(meter=meter)]
dx={}
for parselist in parses:
for parse in parselist:
if not parse: continue
slot_i=0
for pos in parse.positions:
for slot in pos.slots:
slot_i+=1
feat_dicts = [slot.feats, pos.constraintScores, pos.feats]
for feat_dict in feat_dicts:
for k,v in feat_dict.items():
dk = (slot_i,str(k))
if not dk in dx: dx[dk]=[]
dx[dk]+=[v]
def _writegen():
for ((slot_i,k),l) in sorted(dx.items()):
l2=[]
for x in l:
if type(x)==bool:
x=1 if x else 0
elif type(x)==type(None):
x=0
elif type(x) in [str,unicode]:
continue
else:
x=float(x)
if x>1: x=1
l2+=[x]
if not l2: continue
avg=sum(l2) / float(len(l2))
count=sum(l2)
chances=len(l2)
odx={'slot_num':slot_i, 'statistic':k, 'average':avg, 'count':count, 'chances':chances, 'text':self.name}
odx['header']=['slot_num', 'statistic','count','chances','average']
yield odx
name=self.name.replace('.txt','')
ofn=os.path.join(self.dir_results, 'stats','texts',name, name+'.positions.csv')
if not os.path.exists(os.path.split(ofn)[0]): os.makedirs(os.path.split(ofn)[0])
for dx in writegengen(ofn, _writegen):
yield dx
print '>> saved:',ofn |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'iparse'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'meter'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'num_processes'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'arbiter'}, {'id': '13', 'type': 'string', 'children': [], 'value': "'Line'"}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'line_lim'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'block', 'children': ['18', '29', '34', '43', '53', '63', '73', '83', '91', '99', '106', '110', '119', '131', '143', '163', '175', '182', '190', '202', '322']}; {'id': '18', 'type': 'import_from_statement', 'children': ['19', '21', '23', '25', '27']}, {'id': '19', 'type': 'dotted_name', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'Meter'}, {'id': '21', 'type': 'dotted_name', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Meter'}, {'id': '23', 'type': 'dotted_name', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'genDefault'}, {'id': '25', 'type': 'dotted_name', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'parse_ent'}, {'id': '27', 'type': 'dotted_name', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'parse_ent_mp'}, {'id': '29', 'type': 'import_statement', 'children': ['30']}; {'id': '30', 'type': 'aliased_import', 'children': ['31', '33']}, {'id': '31', 'type': 'dotted_name', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'multiprocessing'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'mp'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'meter'}, {'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': 'get_meter'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'meter'}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '52']}, {'id': '45', 'type': 'subscript', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '__parses'}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'meter'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '52', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '62']}, {'id': '55', 'type': 'subscript', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '__bestparses'}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'meter'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '62', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '72']}, {'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': '__boundParses'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'meter'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '72', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '82']}, {'id': '75', 'type': 'subscript', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': '__parsed_ents'}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'meter'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '82', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '90', 'type': 'argument_list', 'children': []}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '96', 'type': 'slice', 'children': ['97', '98']}, {'id': '97', 'type': 'colon', 'children': []}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'line_lim'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'numlines'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'lines'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'init'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'ents'}, {'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': 'ents'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'arbiter'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'smax'}; {'id': '122', 'type': 'call', 'children': ['123', '128']}, {'id': '123', 'type': 'attribute', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '130']}, {'id': '129', 'type': 'string', 'children': [], 'value': "'line_maxsylls'"}; {'id': '130', 'type': 'integer', 'children': [], 'value': '100'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'smin'}; {'id': '134', 'type': 'call', 'children': ['135', '140']}, {'id': '135', 'type': 'attribute', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142']}, {'id': '141', 'type': 'string', 'children': [], 'value': "'line_minsylls'"}; {'id': '142', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'ents'}; {'id': '146', 'type': 'list_comprehension', 'children': ['147', '148', '151']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '148', 'type': 'for_in_clause', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'ents'}, {'id': '151', 'type': 'if_clause', 'children': ['152']}; {'id': '152', 'type': 'boolean_operator', 'children': ['153', '158'], 'value': 'and'}, {'id': '153', 'type': 'comparison_operator', 'children': ['154', '157'], 'value': '>='}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'num_syll'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'smin'}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '162'], 'value': '<='}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'num_syll'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'smax'}, {'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': 'self'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'scansion_prepare'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '172']}, {'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'meter'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'meter'}; {'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'conscious'}; {'id': '174', 'type': 'True', 'children': []}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'numents'}; {'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': 'ents'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'toprint'}, {'id': '185', 'type': 'subscript', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '189', 'type': 'string', 'children': [], 'value': "'print_to_screen'"}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '193', 'type': 'list_comprehension', 'children': ['194', '199']}; {'id': '194', 'type': 'tuple', 'children': ['195', '196', '197', '198']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'ent'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'meter'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'init'}; {'id': '198', 'type': 'False', 'children': []}, {'id': '199', 'type': 'for_in_clause', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'ent'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'ents'}; {'id': '202', 'type': 'if_statement', 'children': ['203', '206', '250']}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': '>'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'num_processes'}, {'id': '205', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '206', 'type': 'block', 'children': ['207', '209', '218', '233']}, {'id': '207', 'type': 'print_statement', 'children': ['208']}; {'id': '208', 'type': 'string', 'children': [], 'value': "'!! MULTIPROCESSING PARSING IS NOT WORKING YET !!'"}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'pool'}; {'id': '212', 'type': 'call', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'mp'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'Pool'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'num_processes'}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'jobs'}, {'id': '221', 'type': 'list_comprehension', 'children': ['222', '230']}; {'id': '222', 'type': 'call', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'pool'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'apply_async'}; {'id': '226', 'type': 'argument_list', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'parse_ent_mp'}; {'id': '228', 'type': 'tuple', 'children': ['229']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '230', 'type': 'for_in_clause', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'objects'}, {'id': '233', 'type': 'for_statement', 'children': ['234', '235', '236']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'jobs'}; {'id': '236', 'type': 'block', 'children': ['237', '243']}, {'id': '237', 'type': 'print_statement', 'children': ['238']}; {'id': '238', 'type': 'call', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'j'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '242', 'type': 'argument_list', 'children': []}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'yield', 'children': ['245']}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '249', 'type': 'argument_list', 'children': []}; {'id': '250', 'type': 'else_clause', 'children': ['251']}, {'id': '251', 'type': 'block', 'children': ['252', '260', '264']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'assignment', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '255', 'type': 'call', 'children': ['256', '259']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '259', 'type': 'argument_list', 'children': []}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'clock_snum'}, {'id': '263', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '264', 'type': 'for_statement', 'children': ['265', '268', '272']}, {'id': '265', 'type': 'pattern_list', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'ei'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'objectx'}; {'id': '268', 'type': 'call', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'objects'}; {'id': '272', 'type': 'block', 'children': ['273', '279', '316']}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'augmented_assignment', 'children': ['275', '276'], 'value': '+='}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'clock_snum'}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'ent'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'num_syll'}, {'id': '279', 'type': 'if_statement', 'children': ['280', '286']}; {'id': '280', 'type': 'boolean_operator', 'children': ['281', '282'], 'value': 'and'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'ei'}; {'id': '282', 'type': 'not_operator', 'children': ['283']}, {'id': '283', 'type': 'binary_operator', 'children': ['284', '285'], 'value': '%'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'ei'}, {'id': '285', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '286', 'type': 'block', 'children': ['287', '295', '308', '312']}, {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'assignment', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'nownow'}; {'id': '290', 'type': 'call', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '294', 'type': 'argument_list', 'children': []}, {'id': '295', 'type': 'if_statement', 'children': ['296', '301']}; {'id': '296', 'type': 'subscript', 'children': ['297', '300']}, {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '300', 'type': 'string', 'children': [], 'value': "'print_to_screen'"}, {'id': '301', 'type': 'block', 'children': ['302']}; {'id': '302', 'type': 'print_statement', 'children': ['303', '304']}, {'id': '303', 'type': 'ERROR', 'children': []}; {'id': '304', 'type': 'chevron', 'children': ['305', '307']}, {'id': '305', 'type': 'ERROR', 'children': ['306']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'parsing'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'nownow'}; {'id': '312', 'type': 'expression_statement', 'children': ['313']}, {'id': '313', 'type': 'assignment', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'clock_snum'}, {'id': '315', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'yield', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'parse_ent_mp'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'objectx'}; {'id': '322', 'type': 'if_statement', 'children': ['323', '328']}, {'id': '323', 'type': 'subscript', 'children': ['324', '327']}; {'id': '324', 'type': 'attribute', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '327', 'type': 'string', 'children': [], 'value': "'print_to_screen'"}; {'id': '328', 'type': 'block', 'children': ['329']}, {'id': '329', 'type': 'print_statement', 'children': ['330', '331', '338']}; {'id': '330', 'type': 'string', 'children': [], 'value': "'>> parsing complete in:'"}, {'id': '331', 'type': 'binary_operator', 'children': ['332', '337'], 'value': '-'}; {'id': '332', 'type': 'call', 'children': ['333', '336']}, {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '336', 'type': 'argument_list', 'children': []}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'now'} | def iparse(self,meter=None,num_processes=1,arbiter='Line',line_lim=None):
from Meter import Meter,genDefault,parse_ent,parse_ent_mp
import multiprocessing as mp
meter=self.get_meter(meter)
self.__parses[meter.id]=[]
self.__bestparses[meter.id]=[]
self.__boundParses[meter.id]=[]
self.__parsed_ents[meter.id]=[]
lines = self.lines()
lines=lines[:line_lim]
numlines = len(lines)
init=self
ents=self.ents(arbiter)
smax=self.config.get('line_maxsylls',100)
smin=self.config.get('line_minsylls',0)
ents = [e for e in ents if e.num_syll >= smin and e.num_syll<=smax]
self.scansion_prepare(meter=meter,conscious=True)
numents=len(ents)
toprint=self.config['print_to_screen']
objects = [(ent,meter,init,False) for ent in ents]
if num_processes>1:
print '!! MULTIPROCESSING PARSING IS NOT WORKING YET !!'
pool = mp.Pool(num_processes)
jobs = [pool.apply_async(parse_ent_mp,(x,)) for x in objects]
for j in jobs:
print j.get()
yield j.get()
else:
now=time.time()
clock_snum=0
for ei,objectx in enumerate(objects):
clock_snum+=ent.num_syll
if ei and not ei%100:
nownow=time.time()
if self.config['print_to_screen']:
print '>> parsing line
now=nownow
clock_snum=0
yield parse_ent_mp(objectx)
if self.config['print_to_screen']:
print '>> parsing complete in:',time.time()-now,'seconds' |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_representation'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'representation'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '15', '169', '198']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'object_dict'}; {'id': '10', 'type': 'dictionary', 'children': []}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'failed'}; {'id': '14', 'type': 'dictionary', 'children': []}, {'id': '15', 'type': 'for_statement', 'children': ['16', '19', '26']}; {'id': '16', 'type': 'pattern_list', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '19', 'type': 'call', 'children': ['20', '25']}; {'id': '20', 'type': 'attribute', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '25', 'type': 'argument_list', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '33']}, {'id': '27', 'type': 'if_statement', 'children': ['28', '31']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'not'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'representation'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'continue_statement', 'children': []}, {'id': '33', 'type': 'try_statement', 'children': ['34', '154']}; {'id': '34', 'type': 'block', 'children': ['35', '57', '65', '71']}, {'id': '35', 'type': 'if_statement', 'children': ['36', '51']}; {'id': '36', 'type': 'parenthesized_expression', 'children': ['37'], 'value': '()'}, {'id': '37', 'type': 'boolean_operator', 'children': ['38', '48'], 'value': 'and'}; {'id': '38', 'type': 'not_operator', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '45']}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'representation'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '45', 'type': 'tuple', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'many'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'raise_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'string', 'children': [], 'value': '"field should be sequence"'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': '_source'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'representation'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '71', 'type': 'if_statement', 'children': ['72', '75', '119']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'many'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'if_statement', 'children': ['77', '81', '97']}, {'id': '77', 'type': 'not_operator', 'children': ['78']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'allow_null'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '87']}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'object_dict'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '87', 'type': 'list_comprehension', 'children': ['88', '94']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'from_representation'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'single_value'}; {'id': '94', 'type': 'for_in_clause', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'single_value'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '97', 'type': 'else_clause', 'children': ['98']}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '104']}, {'id': '101', 'type': 'subscript', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'object_dict'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '104', 'type': 'list_comprehension', 'children': ['105', '116']}, {'id': '105', 'type': 'conditional_expression', 'children': ['106', '112', '115'], 'value': 'if'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'from_representation'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'single_value'}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'is'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'single_value'}; {'id': '114', 'type': 'None', 'children': []}, {'id': '115', 'type': 'None', 'children': []}; {'id': '116', 'type': 'for_in_clause', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'single_value'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '119', 'type': 'else_clause', 'children': ['120']}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'if_statement', 'children': ['122', '126', '138']}; {'id': '122', 'type': 'not_operator', 'children': ['123']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'allow_null'}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '132']}, {'id': '129', 'type': 'subscript', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'object_dict'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'from_representation'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '138', 'type': 'else_clause', 'children': ['139']}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '145']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'object_dict'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '145', 'type': 'conditional_expression', 'children': ['146', '152', '153'], 'value': 'if'}; {'id': '146', 'type': 'call', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'from_representation'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '153', 'type': 'None', 'children': []}; {'id': '154', 'type': 'except_clause', 'children': ['155', '159']}, {'id': '155', 'type': 'as_pattern', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '157', 'type': 'as_pattern_target', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '165']}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'failed'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '169', 'type': 'if_statement', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'failed'}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'try_statement', 'children': ['173', '185']}, {'id': '173', 'type': 'block', 'children': ['174', '181']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'validate'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'object_dict'}, {'id': '181', 'type': 'raise_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'DeserializationError'}; {'id': '184', 'type': 'argument_list', 'children': []}, {'id': '185', 'type': 'except_clause', 'children': ['186', '190']}; {'id': '186', 'type': 'as_pattern', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'DeserializationError'}; {'id': '188', 'type': 'as_pattern_target', 'children': ['189']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '190', 'type': 'block', 'children': ['191', '197']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'failed'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'failed'}, {'id': '197', 'type': 'raise_statement', 'children': []}; {'id': '198', 'type': 'return_statement', 'children': ['199']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'object_dict'} | def from_representation(self, representation):
object_dict = {}
failed = {}
for name, field in self.fields.items():
if name not in representation:
continue
try:
if (
not isinstance(representation[name], (list, tuple)) and
field.many
):
raise ValueError("field should be sequence")
source = _source(name, field)
value = representation[name]
if field.many:
if not field.allow_null:
object_dict[source] = [
field.from_representation(single_value)
for single_value in value
]
else:
object_dict[source] = [
field.from_representation(single_value)
if single_value is not None else None
for single_value in value
]
else:
if not field.allow_null:
object_dict[source] = field.from_representation(value)
else:
object_dict[source] = field.from_representation(
value) if value else None
except ValueError as err:
failed[name] = str(err)
if failed:
try:
self.validate(object_dict)
raise DeserializationError()
except DeserializationError as err:
err.failed = failed
raise
return object_dict |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'require_params'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '185']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '10', 'type': 'dictionary', 'children': []}, {'id': '11', 'type': 'for_statement', 'children': ['12', '15', '22']}; {'id': '12', 'type': 'pattern_list', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'if_statement', 'children': ['24', '33', '77']}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '30'], 'value': 'and'}, {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'not'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'req'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'required'}, {'id': '33', 'type': 'block', 'children': ['34', '65']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'missing'}, {'id': '37', 'type': 'binary_operator', 'children': ['38', '55'], 'value': '-'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '40', 'type': 'generator_expression', 'children': ['41', '42', '47']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '47', 'type': 'if_clause', 'children': ['48']}; {'id': '48', 'type': 'attribute', 'children': ['49', '54']}, {'id': '49', 'type': 'subscript', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'required'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'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': 'req'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'raise_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'HTTPMissingParam'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'string', 'children': [], 'value': '", "'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'missing'}, {'id': '77', 'type': 'elif_clause', 'children': ['78', '87']}; {'id': '78', 'type': 'boolean_operator', 'children': ['79', '84'], 'value': 'or'}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'in'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'req'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'try_statement', 'children': ['89', '155', '168']}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'if_statement', 'children': ['91', '94', '132']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'many'}; {'id': '94', 'type': 'block', 'children': ['95', '121']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '98', 'type': 'boolean_operator', 'children': ['99', '108'], 'value': 'or'}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'req'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'get_param_as_list'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'validated_value'}; {'id': '108', 'type': 'list', 'children': ['109'], 'value': '[\n param.default and\n param.validated_value(param.default)\n ]'}, {'id': '109', 'type': 'boolean_operator', 'children': ['110', '113'], 'value': 'and'}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'validated_value'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '126']}, {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'container'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'values'}; {'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': 'params'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'validated_value'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'req'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'get_param'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '155', 'type': 'except_clause', 'children': ['156', '160']}; {'id': '156', 'type': 'as_pattern', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'ValidationError'}; {'id': '158', 'type': 'as_pattern_target', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'raise_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'as_invalid_param'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '168', 'type': 'except_clause', 'children': ['169', '173']}, {'id': '169', 'type': 'as_pattern', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '171', 'type': 'as_pattern_target', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'raise_statement', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'HTTPInvalidParam'}, {'id': '179', 'type': 'argument_list', 'children': ['180', '184']}; {'id': '180', 'type': 'call', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '185', 'type': 'return_statement', 'children': ['186']} | def require_params(self, req):
params = {}
for name, param in self.params.items():
if name not in req.params and param.required:
missing = set(
p for p in self.params
if self.params[p].required
) - set(req.params.keys())
raise errors.HTTPMissingParam(", ".join(missing))
elif name in req.params or param.default:
try:
if param.many:
values = req.get_param_as_list(
name, param.validated_value
) or [
param.default and
param.validated_value(param.default)
]
params[name] = param.container(values)
else:
params[name] = param.validated_value(
req.get_param(name, default=param.default)
)
except ValidationError as err:
raise err.as_invalid_param(name)
except ValueError as err:
raise errors.HTTPInvalidParam(str(err), name)
return params |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'celf'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '271', '280', '287']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': '"generates an Introspection tree from the given XML string description."'}, {'id': '9', 'type': 'function_definition', 'children': ['10', '11', '15']}; {'id': '10', 'type': 'function_name', 'children': [], 'value': 'from_string_elts'}, {'id': '11', 'type': 'parameters', 'children': ['12', '13', '14']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'celf'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '15', 'type': 'block', 'children': ['16', '30', '59', '63', '203', '264']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'elts'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '21', 'type': 'generator_expression', 'children': ['22', '27']}; {'id': '22', 'type': 'tuple', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '24', 'type': 'subscript', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'child_tags'}, {'id': '33', 'type': 'call', 'children': ['34', '35', '36']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '35', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '36', 'type': 'generator_expression', 'children': ['37', '42']}, {'id': '37', 'type': 'tuple', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'childclass'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'tag_name'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'childclass'}; {'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'childclass'}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '55'], 'value': '+'}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '54']}, {'id': '49', 'type': 'attribute', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'celf'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'tag_elts'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '54', 'type': 'argument_list', 'children': []}, {'id': '55', 'type': 'tuple', 'children': ['56']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'Introspection'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'Annotation'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '62', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '63', 'type': 'for_statement', 'children': ['64', '65', '66']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '66', 'type': 'block', 'children': ['67', '83', '91', '95', '158', '191']}, {'id': '67', 'type': 'if_statement', 'children': ['68', '73']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '72'], 'value': 'not'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'child_tags'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'raise_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '%'}, {'id': '79', 'type': 'string', 'children': [], 'value': '"unrecognized tag %s"'}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'childclass'}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'child_tags'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'childattrs'}; {'id': '94', 'type': 'dictionary', 'children': []}, {'id': '95', 'type': 'for_statement', 'children': ['96', '97', '100']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'childclass'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'tag_attrs'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'if_statement', 'children': ['102', '113', '128']}; {'id': '102', 'type': 'boolean_operator', 'children': ['103', '108'], 'value': 'and'}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'childclass'}, {'id': '107', 'type': 'string', 'children': [], 'value': '"tag_attrs_optional"'}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'in'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'childclass'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'tag_attrs_optional'}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '119']}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'childattrs'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '119', 'type': 'call', 'children': ['120', '125']}; {'id': '120', 'type': 'attribute', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'attrib'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '127', 'type': 'None', 'children': []}; {'id': '128', 'type': 'else_clause', 'children': ['129']}, {'id': '129', 'type': 'block', 'children': ['130', '148']}; {'id': '130', 'type': 'if_statement', 'children': ['131', '136']}, {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'not'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'attrib'}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'raise_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '%'}; {'id': '142', 'type': 'string', 'children': [], 'value': '"missing %s attribute for %s tag"'}, {'id': '143', 'type': 'tuple', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '153']}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'childattrs'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '153', 'type': 'subscript', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'attrib'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '158', 'type': 'if_statement', 'children': ['159', '164']}, {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '161', 'type': 'argument_list', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'childclass'}, {'id': '163', 'type': 'string', 'children': [], 'value': '"attr_convert"'}; {'id': '164', 'type': 'block', 'children': ['165']}, {'id': '165', 'type': 'for_statement', 'children': ['166', '167', '170']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'childclass'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'attr_convert'}; {'id': '170', 'type': 'block', 'children': ['171']}, {'id': '171', 'type': 'if_statement', 'children': ['172', '175']}; {'id': '172', 'type': 'comparison_operator', 'children': ['173', '174'], 'value': 'in'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'childattrs'}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '181']}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'childattrs'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '181', 'type': 'call', 'children': ['182', '187']}; {'id': '182', 'type': 'subscript', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'childclass'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'attr_convert'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'childattrs'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'from_string_elts'}, {'id': '199', 'type': 'argument_list', 'children': ['200', '201', '202']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'childclass'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'childattrs'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '203', 'type': 'for_statement', 'children': ['204', '207', '232']}; {'id': '204', 'type': 'pattern_list', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'child_tag'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'childclass'}, {'id': '207', 'type': 'binary_operator', 'children': ['208', '218'], 'value': '+'}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'call', 'children': ['212', '217']}; {'id': '212', 'type': 'attribute', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'celf'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'tag_elts'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '217', 'type': 'argument_list', 'children': []}; {'id': '218', 'type': 'subscript', 'children': ['219', '227']}, {'id': '219', 'type': 'tuple', 'children': ['220', '221']}; {'id': '220', 'type': 'tuple', 'children': []}, {'id': '221', 'type': 'tuple', 'children': ['222']}; {'id': '222', 'type': 'tuple', 'children': ['223', '224']}, {'id': '223', 'type': 'string', 'children': [], 'value': '"annotations"'}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'Introspection'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'Annotation'}, {'id': '227', 'type': 'comparison_operator', 'children': ['228', '231'], 'value': '!='}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '231', 'type': 'string', 'children': [], 'value': '"annotation"'}; {'id': '232', 'type': 'block', 'children': ['233']}, {'id': '233', 'type': 'for_statement', 'children': ['234', '235', '236']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '236', 'type': 'block', 'children': ['237']}, {'id': '237', 'type': 'if_statement', 'children': ['238', '243']}; {'id': '238', 'type': 'call', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '240', 'type': 'argument_list', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'childclass'}, {'id': '243', 'type': 'block', 'children': ['244', '255']}; {'id': '244', 'type': 'if_statement', 'children': ['245', '248']}, {'id': '245', 'type': 'comparison_operator', 'children': ['246', '247'], 'value': 'not'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'child_tag'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'elts'}; {'id': '248', 'type': 'block', 'children': ['249']}, {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '254']}, {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'elts'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'child_tag'}; {'id': '254', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '262']}, {'id': '257', 'type': 'attribute', 'children': ['258', '261']}; {'id': '258', 'type': 'subscript', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'elts'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'child_tag'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '264', 'type': 'return_statement', 'children': ['265', '266']}, {'id': '265', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '266', 'type': 'call', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'celf'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}, {'id': '269', 'type': 'dictionary_splat', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'elts'}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '274', 'type': 'call', 'children': ['275', '278']}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'XMLElementTree'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'fromstring'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '280', 'type': 'assert_statement', 'children': ['281', '286']}, {'id': '281', 'type': 'comparison_operator', 'children': ['282', '285'], 'value': '=='}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '285', 'type': 'string', 'children': [], 'value': '"node"'}; {'id': '286', 'type': 'string', 'children': [], 'value': '"root of introspection tree must be <node> tag"'}, {'id': '287', 'type': 'return_statement', 'children': ['288', '289']}; {'id': '288', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'from_string_elts'}, {'id': '291', 'type': 'argument_list', 'children': ['292', '293', '294']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'Introspection'}, {'id': '293', 'type': 'dictionary', 'children': []} | def parse(celf, s) :
"generates an Introspection tree from the given XML string description."
def from_string_elts(celf, attrs, tree) :
elts = dict((k, attrs[k]) for k in attrs)
child_tags = dict \
(
(childclass.tag_name, childclass)
for childclass in tuple(celf.tag_elts.values()) + (Introspection.Annotation,)
)
children = []
for child in tree :
if child.tag not in child_tags :
raise KeyError("unrecognized tag %s" % child.tag)
childclass = child_tags[child.tag]
childattrs = {}
for attrname in childclass.tag_attrs :
if hasattr(childclass, "tag_attrs_optional") and attrname in childclass.tag_attrs_optional :
childattrs[attrname] = child.attrib.get(attrname, None)
else :
if attrname not in child.attrib :
raise ValueError("missing %s attribute for %s tag" % (attrname, child.tag))
childattrs[attrname] = child.attrib[attrname]
if hasattr(childclass, "attr_convert") :
for attr in childclass.attr_convert :
if attr in childattrs :
childattrs[attr] = childclass.attr_convert[attr](childattrs[attr])
children.append(from_string_elts(childclass, childattrs, child))
for child_tag, childclass in tuple(celf.tag_elts.items()) + ((), (("annotations", Introspection.Annotation),))[tree.tag != "annotation"] :
for child in children :
if isinstance(child, childclass) :
if child_tag not in elts :
elts[child_tag] = []
elts[child_tag].append(child)
return \
celf(**elts)
tree = XMLElementTree.fromstring(s)
assert tree.tag == "node", "root of introspection tree must be <node> tag"
return \
from_string_elts(Introspection, {}, tree) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'unparse'}, {'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': 'indent_step'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'max_linelen'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '72'}, {'id': '11', 'type': 'block', 'children': ['12', '14', '22', '352', '361', '368', '389', '396', '408', '420', '427']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'string', 'children': [], 'value': '"returns an XML string description of this Introspection tree."'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'io'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'StringIO'}, {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'function_definition', 'children': ['23', '24', '27']}, {'id': '23', 'type': 'function_name', 'children': [], 'value': 'to_string'}; {'id': '24', 'type': 'parameters', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '27', 'type': 'block', 'children': ['28', '34', '38', '125', '169', '182', '284', '295', '302']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'tag_name'}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'tag_name'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '37', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '43']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'tag_attrs'}, {'id': '43', 'type': 'block', 'children': ['44', '52']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '!='}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57', '111']}, {'id': '57', 'type': 'if_statement', 'children': ['58', '65', '72', '86']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'enum'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'Enum'}, {'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': 'attr'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '72', 'type': 'elif_clause', 'children': ['73', '78']}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'Type'}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'unparse_signature'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '86', 'type': 'elif_clause', 'children': ['87', '93']}, {'id': '87', 'type': 'not_operator', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'raise_statement', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '100'], 'value': '%'}, {'id': '99', 'type': 'string', 'children': [], 'value': '"unexpected attribute type %s for %s"'}; {'id': '100', 'type': 'tuple', 'children': ['101', '107']}, {'id': '101', 'type': 'attribute', 'children': ['102', '106']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': '__name__'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'repr'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'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': 'attrs'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '%'}; {'id': '118', 'type': 'string', 'children': [], 'value': '"%s=%s"'}, {'id': '119', 'type': 'tuple', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'quote_xml_attr'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128', '129']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'has_elts'}; {'id': '128', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '129', 'type': 'parenthesized_expression', 'children': ['130'], 'value': '()'}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '168'], 'value': '!='}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'sum'}, {'id': '133', 'type': 'generator_expression', 'children': ['134', '142']}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '139', 'type': 'argument_list', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '142', 'type': 'for_in_clause', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '144', 'type': 'binary_operator', 'children': ['145', '155'], 'value': '+'}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '154']}, {'id': '149', 'type': 'attribute', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'tag_elts'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '154', 'type': 'argument_list', 'children': []}, {'id': '155', 'type': 'subscript', 'children': ['156', '160']}; {'id': '156', 'type': 'tuple', 'children': ['157', '158']}, {'id': '157', 'type': 'tuple', 'children': []}; {'id': '158', 'type': 'tuple', 'children': ['159']}, {'id': '159', 'type': 'string', 'children': [], 'value': '"annotations"'}; {'id': '160', 'type': 'not_operator', 'children': ['161']}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '163', 'type': 'argument_list', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'Introspection'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'Annotation'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'binary_operator', 'children': ['176', '181'], 'value': '+'}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '180'], 'value': '+'}, {'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '*'}; {'id': '178', 'type': 'string', 'children': [], 'value': '" "'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '180', 'type': 'string', 'children': [], 'value': '"<"'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'tag_name'}; {'id': '182', 'type': 'if_statement', 'children': ['183', '217', '264']}, {'id': '183', 'type': 'parenthesized_expression', 'children': ['184'], 'value': '()'}; {'id': '184', 'type': 'boolean_operator', 'children': ['185', '188'], 'value': 'and'}, {'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': '!='}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'max_linelen'}, {'id': '187', 'type': 'None', 'children': []}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '216'], 'value': '>'}, {'id': '189', 'type': 'binary_operator', 'children': ['190', '212'], 'value': '+'}; {'id': '190', 'type': 'binary_operator', 'children': ['191', '211'], 'value': '+'}, {'id': '191', 'type': 'binary_operator', 'children': ['192', '198'], 'value': '+'}; {'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '+'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '194', 'type': 'call', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'tag_name'}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '200', 'type': 'generator_expression', 'children': ['201', '208']}, {'id': '201', 'type': 'parenthesized_expression', 'children': ['202'], 'value': '()'}; {'id': '202', 'type': 'binary_operator', 'children': ['203', '207'], 'value': '+'}, {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '207', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '208', 'type': 'for_in_clause', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '211', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'has_elts'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'max_linelen'}, {'id': '217', 'type': 'block', 'children': ['218', '225', '255']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'string', 'children': [], 'value': '"\\n"'}, {'id': '225', 'type': 'for_statement', 'children': ['226', '227', '228']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'attr'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'attrs'}; {'id': '228', 'type': 'block', 'children': ['229', '241', '248']}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '234']}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}, {'id': '235', 'type': 'binary_operator', 'children': ['236', '237'], 'value': '*'}; {'id': '236', 'type': 'string', 'children': [], 'value': '" "'}, {'id': '237', 'type': 'parenthesized_expression', 'children': ['238'], 'value': '()'}; {'id': '238', 'type': 'binary_operator', 'children': ['239', '240'], 'value': '+'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'indent_step'}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '246']}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'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': 'out'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'string', 'children': [], 'value': '"\\n"'}, {'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': 'out'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'binary_operator', 'children': ['262', '263'], 'value': '*'}; {'id': '262', 'type': 'string', 'children': [], 'value': '" "'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '264', 'type': 'else_clause', 'children': ['265']}, {'id': '265', 'type': 'block', 'children': ['266']}; {'id': '266', 'type': 'for_statement', 'children': ['267', '268', '269']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '269', 'type': 'block', 'children': ['270', '277']}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'string', 'children': [], 'value': '" "'}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'call', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '284', 'type': 'if_statement', 'children': ['285', '287']}, {'id': '285', 'type': 'not_operator', 'children': ['286']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'has_elts'}, {'id': '287', 'type': 'block', 'children': ['288']}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}, {'id': '289', 'type': 'call', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '293', 'type': 'argument_list', 'children': ['294']}; {'id': '294', 'type': 'string', 'children': [], 'value': '"/"'}, {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'call', 'children': ['297', '300']}, {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}, {'id': '301', 'type': 'string', 'children': [], 'value': '">\\n"'}; {'id': '302', 'type': 'if_statement', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'has_elts'}; {'id': '304', 'type': 'block', 'children': ['305', '337']}, {'id': '305', 'type': 'for_statement', 'children': ['306', '307', '320']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'attrname'}, {'id': '307', 'type': 'binary_operator', 'children': ['308', '318'], 'value': '+'}; {'id': '308', 'type': 'call', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}, {'id': '311', 'type': 'call', 'children': ['312', '317']}; {'id': '312', 'type': 'attribute', 'children': ['313', '316']}, {'id': '313', 'type': 'attribute', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'tag_elts'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '317', 'type': 'argument_list', 'children': []}; {'id': '318', 'type': 'list', 'children': ['319'], 'value': '["annotations"]'}, {'id': '319', 'type': 'string', 'children': [], 'value': '"annotations"'}; {'id': '320', 'type': 'block', 'children': ['321']}, {'id': '321', 'type': 'for_statement', 'children': ['322', '323', '328']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'elt'}, {'id': '323', 'type': 'call', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '325', 'type': 'argument_list', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'attrname'}; {'id': '328', 'type': 'block', 'children': ['329']}, {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'call', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'to_string'}; {'id': '332', 'type': 'argument_list', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '334', 'type': 'binary_operator', 'children': ['335', '336'], 'value': '+'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'indent_step'}, {'id': '337', 'type': 'expression_statement', 'children': ['338']}; {'id': '338', 'type': 'call', 'children': ['339', '342']}, {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '342', 'type': 'argument_list', 'children': ['343']}, {'id': '343', 'type': 'binary_operator', 'children': ['344', '351'], 'value': '+'}; {'id': '344', 'type': 'binary_operator', 'children': ['345', '350'], 'value': '+'}, {'id': '345', 'type': 'binary_operator', 'children': ['346', '349'], 'value': '+'}; {'id': '346', 'type': 'binary_operator', 'children': ['347', '348'], 'value': '*'}, {'id': '347', 'type': 'string', 'children': [], 'value': '" "'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'indent'}, {'id': '349', 'type': 'string', 'children': [], 'value': '"</"'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'tag_name'}, {'id': '351', 'type': 'string', 'children': [], 'value': '">\\n"'}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}, {'id': '353', 'type': 'call', 'children': ['354', '357']}; {'id': '354', 'type': 'attribute', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '357', 'type': 'argument_list', 'children': ['358']}; {'id': '358', 'type': 'attribute', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'DBUS'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE'}, {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'call', 'children': ['363', '366']}, {'id': '363', 'type': 'attribute', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '366', 'type': 'argument_list', 'children': ['367']}, {'id': '367', 'type': 'string', 'children': [], 'value': '"<node"'}; {'id': '368', 'type': 'if_statement', 'children': ['369', '374']}, {'id': '369', 'type': 'comparison_operator', 'children': ['370', '373'], 'value': '!='}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '373', 'type': 'None', 'children': []}; {'id': '374', 'type': 'block', 'children': ['375']}, {'id': '375', 'type': 'expression_statement', 'children': ['376']}; {'id': '376', 'type': 'call', 'children': ['377', '380']}, {'id': '377', 'type': 'attribute', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '380', 'type': 'argument_list', 'children': ['381']}, {'id': '381', 'type': 'binary_operator', 'children': ['382', '383'], 'value': '%'}; {'id': '382', 'type': 'string', 'children': [], 'value': '" name=%s"'}, {'id': '383', 'type': 'call', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'quote_xml_attr'}, {'id': '385', 'type': 'argument_list', 'children': ['386']}; {'id': '386', 'type': 'attribute', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '389', 'type': 'expression_statement', 'children': ['390']}; {'id': '390', 'type': 'call', 'children': ['391', '394']}, {'id': '391', 'type': 'attribute', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'out'}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '394', 'type': 'argument_list', 'children': ['395']}, {'id': '395', 'type': 'string', 'children': [], 'value': '">\\n"'}; {'id': '396', 'type': 'for_statement', 'children': ['397', '398', '401']}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '398', 'type': 'attribute', 'children': ['399', '400']}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'interfaces'}, {'id': '401', 'type': 'block', 'children': ['402']}; {'id': '402', 'type': 'expression_statement', 'children': ['403']}, {'id': '403', 'type': 'call', 'children': ['404', '405']}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'to_string'}, {'id': '405', 'type': 'argument_list', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'elt'}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'indent_step'}; {'id': '408', 'type': 'for_statement', 'children': ['409', '410', '413']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '410', 'type': 'attribute', 'children': ['411', '412']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '413', 'type': 'block', 'children': ['414']}; {'id': '414', 'type': 'expression_statement', 'children': ['415']}, {'id': '415', 'type': 'call', 'children': ['416', '417']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'to_string'}, {'id': '417', 'type': 'argument_list', 'children': ['418', '419']}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'elt'}, {'id': '419', 'type': 'identifier', 'children': [], 'value': 'indent_step'}; {'id': '420', 'type': 'expression_statement', 'children': ['421']}, {'id': '421', 'type': 'call', 'children': ['422', '425']}; {'id': '422', 'type': 'attribute', 'children': ['423', '424']}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '425', 'type': 'argument_list', 'children': ['426']}; {'id': '426', 'type': 'string', 'children': [], 'value': '"</node>\\n"'}, {'id': '427', 'type': 'return_statement', 'children': ['428', '429']}; {'id': '428', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '429', 'type': 'call', 'children': ['430', '433']}; {'id': '430', 'type': 'attribute', 'children': ['431', '432']}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'getvalue'}, {'id': '433', 'type': 'argument_list', 'children': []} | def unparse(self, indent_step = 4, max_linelen = 72) :
"returns an XML string description of this Introspection tree."
out = io.StringIO()
def to_string(obj, indent) :
tag_name = obj.tag_name
attrs = []
for attrname in obj.tag_attrs :
attr = getattr(obj, attrname)
if attr != None :
if isinstance(attr, enum.Enum) :
attr = attr.value
elif isinstance(attr, Type) :
attr = unparse_signature(attr)
elif not isinstance(attr, str) :
raise TypeError("unexpected attribute type %s for %s" % (type(attr).__name__, repr(attr)))
attrs.append("%s=%s" % (attrname, quote_xml_attr(attr)))
has_elts = \
(
sum
(
len(getattr(obj, attrname))
for attrname in
tuple(obj.tag_elts.keys())
+
((), ("annotations",))
[not isinstance(obj, Introspection.Annotation)]
)
!=
0
)
out.write(" " * indent + "<" + tag_name)
if (
max_linelen != None
and
indent
+
len(tag_name)
+
sum((len(s) + 1) for s in attrs)
+
2
+
int(has_elts)
>
max_linelen
) :
out.write("\n")
for attr in attrs :
out.write(" " * (indent + indent_step))
out.write(attr)
out.write("\n")
out.write(" " * indent)
else :
for attr in attrs :
out.write(" ")
out.write(attr)
if not has_elts :
out.write("/")
out.write(">\n")
if has_elts :
for attrname in sorted(obj.tag_elts.keys()) + ["annotations"] :
for elt in getattr(obj, attrname) :
to_string(elt, indent + indent_step)
out.write(" " * indent + "</" + tag_name + ">\n")
out.write(DBUS.INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE)
out.write("<node")
if self.name != None :
out.write(" name=%s" % quote_xml_attr(self.name))
out.write(">\n")
for elt in self.interfaces :
to_string(elt, indent_step)
for elt in self.nodes :
to_string(elt, indent_step)
out.write("</node>\n")
return \
out.getvalue() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'AddMethod'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'interface'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'in_sig'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'out_sig'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '10', 'type': 'block', 'children': ['11', '13', '23', '35', '58', '75', '84', '90', '108', '124']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': '\'\'\'Add a method to this object\n interface: D-Bus interface to add this to. For convenience you can\n specify \'\' here to add the method to the object\'s main\n interface (as specified on construction).\n name: Name of the method\n in_sig: Signature of input arguments; for example "ias" for a method\n that takes an int32 and a string array as arguments; see\n http://dbus.freedesktop.org/doc/dbus-specification.html\n out_sig: Signature of output arguments; for example "s" for a method\n that returns a string; use \'\' for methods that do not return\n anything.\n code: Python 3 code to run in the method call; you have access to the\n arguments through the "args" list, and can set the return value\n by assigning a value to the "ret" variable. You can also read the\n global "objects" variable, which is a dictionary mapping object\n paths to DBusMockObject instances.\n For keeping state across method calls, you are free to use normal\n Python members of the "self" object, which will be persistent for\n the whole mock\'s life time. E. g. you can have a method with\n "self.my_state = True", and another method that returns it with\n "ret = self.my_state".\n When specifying \'\', the method will not do anything (except\n logging) and return None.\n \'\'\''}, {'id': '13', 'type': 'if_statement', 'children': ['14', '16']}; {'id': '14', 'type': 'not_operator', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'interface'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'interface'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'interface'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'n_args'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'dbus'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'Signature'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'in_sig'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '38', 'type': 'lambda', 'children': ['39', '45']}, {'id': '39', 'type': 'lambda_parameters', 'children': ['40', '41', '43']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'list_splat_pattern', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '43', 'type': 'dictionary_splat_pattern', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'DBusMockObject'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'mock_method'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52', '53', '54', '56']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'interface'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'in_sig'}; {'id': '54', 'type': 'list_splat', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '56', 'type': 'dictionary_splat', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'dbus_method'}, {'id': '61', 'type': 'call', 'children': ['62', '73']}; {'id': '62', 'type': 'call', 'children': ['63', '68']}, {'id': '63', 'type': 'attribute', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'dbus'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'interface'}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'out_signature'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'out_sig'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'dbus_method'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'dbus_method'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': '_dbus_in_signature'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'in_sig'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'dbus_method'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': '_dbus_args'}, {'id': '95', 'type': 'list_comprehension', 'children': ['96', '99']}; {'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '%'}, {'id': '97', 'type': 'string', 'children': [], 'value': "'arg%i'"}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '99', 'type': 'for_in_clause', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '+'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'n_args'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'if_statement', 'children': ['109', '114']}, {'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': '=='}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'interface'}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'interface'}; {'id': '114', 'type': 'block', 'children': ['115']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '122', '123']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'dbus_method'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '140']}; {'id': '126', 'type': 'subscript', 'children': ['127', '136']}, {'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': 'methods'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'setdefault'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'interface'}, {'id': '135', 'type': 'dictionary', 'children': []}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '140', 'type': 'tuple', 'children': ['141', '142', '143', '144']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'in_sig'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'out_sig'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'code'} | def AddMethod(self, interface, name, in_sig, out_sig, code):
'''Add a method to this object
interface: D-Bus interface to add this to. For convenience you can
specify '' here to add the method to the object's main
interface (as specified on construction).
name: Name of the method
in_sig: Signature of input arguments; for example "ias" for a method
that takes an int32 and a string array as arguments; see
http://dbus.freedesktop.org/doc/dbus-specification.html
out_sig: Signature of output arguments; for example "s" for a method
that returns a string; use '' for methods that do not return
anything.
code: Python 3 code to run in the method call; you have access to the
arguments through the "args" list, and can set the return value
by assigning a value to the "ret" variable. You can also read the
global "objects" variable, which is a dictionary mapping object
paths to DBusMockObject instances.
For keeping state across method calls, you are free to use normal
Python members of the "self" object, which will be persistent for
the whole mock's life time. E. g. you can have a method with
"self.my_state = True", and another method that returns it with
"ret = self.my_state".
When specifying '', the method will not do anything (except
logging) and return None.
'''
if not interface:
interface = self.interface
n_args = len(dbus.Signature(in_sig))
method = lambda self, *args, **kwargs: DBusMockObject.mock_method(
self, interface, name, in_sig, *args, **kwargs)
dbus_method = dbus.service.method(interface,
out_signature=out_sig)(method)
dbus_method.__name__ = str(name)
dbus_method._dbus_in_signature = in_sig
dbus_method._dbus_args = ['arg%i' % i for i in range(1, n_args + 1)]
if interface == self.interface:
setattr(self.__class__, name, dbus_method)
self.methods.setdefault(interface, {})[str(name)] = (in_sig, out_sig, code, dbus_method) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'AddTemplate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '7', 'type': 'block', 'children': ['8', '10', '44', '61', '134', '143', '151', '157']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': '\'\'\'Load a template into the mock.\n python-dbusmock ships a set of standard mocks for common system\n services such as UPower and NetworkManager. With these the actual tests\n become a lot simpler, as they only have to set up the particular\n properties for the tests, and not the skeleton of common properties,\n interfaces, and methods.\n template: Name of the template to load or the full path to a *.py file\n for custom templates. See "pydoc dbusmock.templates" for a\n list of available templates from python-dbusmock package, and\n "pydoc dbusmock.templates.NAME" for documentation about\n template NAME.\n parameters: A parameter (string) → value (variant) map, for\n parameterizing templates. Each template can define their\n own, see documentation of that particular template for\n details.\n \'\'\''}; {'id': '10', 'type': 'try_statement', 'children': ['11', '19']}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'load_module'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'template'}, {'id': '19', 'type': 'except_clause', 'children': ['20', '24']}; {'id': '20', 'type': 'as_pattern', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ImportError'}; {'id': '22', 'type': 'as_pattern_target', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'raise_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '32']}, {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dbus'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'exceptions'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'DBusException'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '41']}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'Cannot add template %s: %s'"}, {'id': '35', 'type': 'tuple', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'template'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'org.freedesktop.DBus.Mock.TemplateError'"}; {'id': '44', 'type': 'if_statement', 'children': ['45', '54']}, {'id': '45', 'type': 'boolean_operator', 'children': ['46', '51'], 'value': 'and'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'IS_OBJECT_MANAGER'"}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'IS_OBJECT_MANAGER'}; {'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': '_set_up_object_manager'}; {'id': '60', 'type': 'argument_list', 'children': []}, {'id': '61', 'type': 'for_statement', 'children': ['62', '63', '67']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'symbol'}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'dir'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '67', 'type': 'block', 'children': ['68', '76']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'symbol'}; {'id': '76', 'type': 'if_statement', 'children': ['77', '97']}, {'id': '77', 'type': 'parenthesized_expression', 'children': ['78'], 'value': '()'}; {'id': '78', 'type': 'boolean_operator', 'children': ['79', '85'], 'value': 'and'}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'in'}; {'id': '80', 'type': 'string', 'children': [], 'value': "'_dbus_interface'"}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'dir'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '85', 'type': 'parenthesized_expression', 'children': ['86'], 'value': '()'}; {'id': '86', 'type': 'boolean_operator', 'children': ['87', '93'], 'value': 'or'}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'not'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'_dbus_is_signal'"}, {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'dir'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '93', 'type': 'not_operator', 'children': ['94']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': '_dbus_is_signal'}, {'id': '97', 'type': 'block', 'children': ['98', '107']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '105', '106']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'symbol'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '125']}, {'id': '109', 'type': 'subscript', 'children': ['110', '121']}; {'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': 'methods'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'setdefault'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': '_dbus_interface'}; {'id': '120', 'type': 'dictionary', 'children': []}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'symbol'}, {'id': '125', 'type': 'tuple', 'children': ['126', '129', '132', '133']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': '_dbus_in_signature'}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': '_dbus_out_signature'}; {'id': '132', 'type': 'string', 'children': [], 'value': "''"}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '134', 'type': 'if_statement', 'children': ['135', '138']}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': 'is'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '137', 'type': 'None', 'children': []}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '142', 'type': 'dictionary', 'children': []}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': '_template'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'template'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': '_template_parameters'} | def AddTemplate(self, template, parameters):
'''Load a template into the mock.
python-dbusmock ships a set of standard mocks for common system
services such as UPower and NetworkManager. With these the actual tests
become a lot simpler, as they only have to set up the particular
properties for the tests, and not the skeleton of common properties,
interfaces, and methods.
template: Name of the template to load or the full path to a *.py file
for custom templates. See "pydoc dbusmock.templates" for a
list of available templates from python-dbusmock package, and
"pydoc dbusmock.templates.NAME" for documentation about
template NAME.
parameters: A parameter (string) → value (variant) map, for
parameterizing templates. Each template can define their
own, see documentation of that particular template for
details.
'''
try:
module = load_module(template)
except ImportError as e:
raise dbus.exceptions.DBusException('Cannot add template %s: %s' % (template, str(e)),
name='org.freedesktop.DBus.Mock.TemplateError')
if hasattr(module, 'IS_OBJECT_MANAGER') and module.IS_OBJECT_MANAGER:
self._set_up_object_manager()
for symbol in dir(module):
fn = getattr(module, symbol)
if ('_dbus_interface' in dir(fn) and ('_dbus_is_signal' not in dir(fn) or not fn._dbus_is_signal)):
setattr(self.__class__, symbol, fn)
self.methods.setdefault(fn._dbus_interface, {})[str(symbol)] = (
fn._dbus_in_signature,
fn._dbus_out_signature, '', fn
)
if parameters is None:
parameters = {}
module.load(self, parameters)
self._template = template
self._template_parameters = parameters |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'format_args'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '6', 'type': 'block', 'children': ['7', '9', '195', '199', '217', '226']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'string', 'children': [], 'value': "'''Format a D-Bus argument tuple into an appropriate logging string.'''"}, {'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'function_name', 'children': [], 'value': 'format_arg'}, {'id': '11', 'type': 'parameters', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '13', 'type': 'block', 'children': ['14', '31', '48', '66', '82', '109', '134', '190']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '22']}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dbus'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Boolean'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'return_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '31', 'type': 'if_statement', 'children': ['32', '39']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dbus'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'Byte'}, {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'return_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '60']}, {'id': '49', 'type': 'boolean_operator', 'children': ['50', '55'], 'value': 'or'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'long'}; {'id': '60', 'type': 'block', 'children': ['61']}, {'id': '61', 'type': 'return_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '72']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '81'], 'value': '+'}, {'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '+'}; {'id': '76', 'type': 'string', 'children': [], 'value': '\'"\''}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '81', 'type': 'string', 'children': [], 'value': '\'"\''}; {'id': '82', 'type': 'if_statement', 'children': ['83', '88']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'unicode'}; {'id': '88', 'type': 'block', 'children': ['89']}, {'id': '89', 'type': 'return_statement', 'children': ['90']}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '108'], 'value': '+'}, {'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '+'}; {'id': '92', 'type': 'string', 'children': [], 'value': '\'"\''}, {'id': '93', 'type': 'subscript', 'children': ['94', '103']}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'encode'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'string', 'children': [], 'value': "'UTF-8'"}, {'id': '103', 'type': 'slice', 'children': ['104', '105', '106']}; {'id': '104', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '105', 'type': 'colon', 'children': []}; {'id': '106', 'type': 'unary_operator', 'children': ['107'], 'value': '-'}, {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'string', 'children': [], 'value': '\'"\''}, {'id': '109', 'type': 'if_statement', 'children': ['110', '115']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'return_statement', 'children': ['117']}, {'id': '117', 'type': 'binary_operator', 'children': ['118', '133'], 'value': '+'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '+'}, {'id': '119', 'type': 'string', 'children': [], 'value': "'['"}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'string', 'children': [], 'value': "', '"}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'list_comprehension', 'children': ['126', '130']}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'format_arg'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '130', 'type': 'for_in_clause', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '133', 'type': 'string', 'children': [], 'value': "']'"}; {'id': '134', 'type': 'if_statement', 'children': ['135', '140']}, {'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': 'a'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '140', 'type': 'block', 'children': ['141', '145', '149', '186']}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'fmta'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'{'"}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'first'}; {'id': '148', 'type': 'True', 'children': []}, {'id': '149', 'type': 'for_statement', 'children': ['150', '153', '158']}; {'id': '150', 'type': 'pattern_list', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'v'}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '157', 'type': 'argument_list', 'children': []}; {'id': '158', 'type': 'block', 'children': ['159', '172']}, {'id': '159', 'type': 'if_statement', 'children': ['160', '161', '166']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'first'}, {'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': 'first'}, {'id': '165', 'type': 'False', 'children': []}; {'id': '166', 'type': 'else_clause', 'children': ['167']}, {'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': 'fmta'}, {'id': '171', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'augmented_assignment', 'children': ['174', '175'], 'value': '+='}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'fmta'}, {'id': '175', 'type': 'binary_operator', 'children': ['176', '182'], 'value': '+'}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '181'], 'value': '+'}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'format_arg'}, {'id': '179', 'type': 'argument_list', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '181', 'type': 'string', 'children': [], 'value': "': '"}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'format_arg'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '186', 'type': 'return_statement', 'children': ['187']}, {'id': '187', 'type': 'binary_operator', 'children': ['188', '189'], 'value': '+'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'fmta'}, {'id': '189', 'type': 'string', 'children': [], 'value': "'}'"}; {'id': '190', 'type': 'return_statement', 'children': ['191']}, {'id': '191', 'type': 'call', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'repr'}, {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '198', 'type': 'string', 'children': [], 'value': "''"}, {'id': '199', 'type': 'for_statement', 'children': ['200', '201', '202']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '202', 'type': 'block', 'children': ['203', '210']}, {'id': '203', 'type': 'if_statement', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'augmented_assignment', 'children': ['208', '209'], 'value': '+='}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '209', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'augmented_assignment', 'children': ['212', '213'], 'value': '+='}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '213', 'type': 'call', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'format_arg'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '217', 'type': 'if_statement', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '219', 'type': 'block', 'children': ['220']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '223', 'type': 'binary_operator', 'children': ['224', '225'], 'value': '+'}; {'id': '224', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '226', 'type': 'return_statement', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 's'} | def format_args(self, args):
'''Format a D-Bus argument tuple into an appropriate logging string.'''
def format_arg(a):
if isinstance(a, dbus.Boolean):
return str(bool(a))
if isinstance(a, dbus.Byte):
return str(int(a))
if isinstance(a, int) or isinstance(a, long):
return str(a)
if isinstance(a, str):
return '"' + str(a) + '"'
if isinstance(a, unicode):
return '"' + repr(a.encode('UTF-8'))[1:-1] + '"'
if isinstance(a, list):
return '[' + ', '.join([format_arg(x) for x in a]) + ']'
if isinstance(a, dict):
fmta = '{'
first = True
for k, v in a.items():
if first:
first = False
else:
fmta += ', '
fmta += format_arg(k) + ': ' + format_arg(v)
return fmta + '}'
return repr(a)
s = ''
for a in args:
if s:
s += ' '
s += format_arg(a)
if s:
s = ' ' + s
return s |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'Introspect'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'object_path'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'connection'}, {'id': '7', 'type': 'block', 'children': ['8', '10', '26', '34', '42', '78', '86', '101', '110', '207', '227', '235']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'string', 'children': [], 'value': "'''Return XML description of this object's interfaces, methods and signals.\n This wraps dbus-python's Introspect() method to include the dynamic\n methods and properties.\n '''"}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '13', 'type': 'binary_operator', 'children': ['14', '21'], 'value': '+'}; {'id': '14', 'type': 'binary_operator', 'children': ['15', '20'], 'value': '+'}, {'id': '15', 'type': 'attribute', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '__module__'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'.'"}, {'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': '__class__'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'orig_interfaces'}, {'id': '29', 'type': 'subscript', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_dbus_class_table'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'mock_interfaces'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'orig_interfaces'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'for_statement', 'children': ['43', '46', '53']}, {'id': '43', 'type': 'pattern_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'interface'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'methods'}; {'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': 'methods'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '52', 'type': 'argument_list', 'children': []}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'for_statement', 'children': ['55', '56', '57']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'methods'}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '69']}; {'id': '60', 'type': 'subscript', 'children': ['61', '68']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'mock_interfaces'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'setdefault'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'interface'}, {'id': '67', 'type': 'dictionary', 'children': []}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '69', 'type': 'subscript', 'children': ['70', '77']}; {'id': '70', 'type': 'subscript', 'children': ['71', '76']}, {'id': '71', 'type': 'subscript', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'methods'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'interface'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '77', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '85']}; {'id': '80', 'type': 'subscript', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': '_dbus_class_table'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'mock_interfaces'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'xml'}, {'id': '89', 'type': 'call', 'children': ['90', '97']}; {'id': '90', 'type': 'attribute', 'children': ['91', '96']}, {'id': '91', 'type': 'attribute', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'dbus'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'Object'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'Introspect'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99', '100']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'object_path'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'connection'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'ElementTree'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'fromstring'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'xml'}; {'id': '110', 'type': 'for_statement', 'children': ['111', '112', '115']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'props'}, {'id': '115', 'type': 'block', 'children': ['116', '127', '152']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'interface'}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '%'}, {'id': '125', 'type': 'string', 'children': [], 'value': '".//interface[@name=\'%s\']"'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '127', 'type': 'if_statement', 'children': ['128', '131']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': 'is'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'interface'}; {'id': '130', 'type': 'None', 'children': []}, {'id': '131', 'type': 'block', 'children': ['132', '145']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'interface'}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'ElementTree'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'Element'}, {'id': '139', 'type': 'argument_list', 'children': ['140', '141']}; {'id': '140', 'type': 'string', 'children': [], 'value': '"interface"'}, {'id': '141', 'type': 'dictionary', 'children': ['142']}; {'id': '142', 'type': 'pair', 'children': ['143', '144']}, {'id': '143', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'name'}, {'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': 'tree'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'interface'}; {'id': '152', 'type': 'for_statement', 'children': ['153', '156', '165']}, {'id': '153', 'type': 'pattern_list', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '156', 'type': 'call', 'children': ['157', '164']}, {'id': '157', 'type': 'attribute', 'children': ['158', '163']}; {'id': '158', 'type': 'subscript', 'children': ['159', '162']}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '164', 'type': 'argument_list', 'children': []}, {'id': '165', 'type': 'block', 'children': ['166', '172', '200']}; {'id': '166', 'type': 'if_statement', 'children': ['167', '170']}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'is'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '169', 'type': 'None', 'children': []}; {'id': '170', 'type': 'block', 'children': ['171']}, {'id': '171', 'type': 'continue_statement', 'children': []}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'elem'}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'ElementTree'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'Element'}, {'id': '179', 'type': 'argument_list', 'children': ['180', '181']}; {'id': '180', 'type': 'string', 'children': [], 'value': '"property"'}, {'id': '181', 'type': 'dictionary', 'children': ['182', '185', '197']}; {'id': '182', 'type': 'pair', 'children': ['183', '184']}, {'id': '183', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '185', 'type': 'pair', 'children': ['186', '187']}; {'id': '186', 'type': 'string', 'children': [], 'value': '"type"'}, {'id': '187', 'type': 'call', 'children': ['188', '195']}; {'id': '188', 'type': 'attribute', 'children': ['189', '194']}, {'id': '189', 'type': 'attribute', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'dbus'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'lowlevel'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'Message'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'guess_signature'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '197', 'type': 'pair', 'children': ['198', '199']}; {'id': '198', 'type': 'string', 'children': [], 'value': '"access"'}, {'id': '199', 'type': 'string', 'children': [], 'value': '"readwrite"'}; {'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': 'interface'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'elem'}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'xml'}; {'id': '210', 'type': 'call', 'children': ['211', '225']}, {'id': '211', 'type': 'attribute', 'children': ['212', '224']}; {'id': '212', 'type': 'call', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'ElementTree'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'tostring'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '218', '221']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '220', 'type': 'string', 'children': [], 'value': "'utf8'"}, {'id': '221', 'type': 'keyword_argument', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '223', 'type': 'string', 'children': [], 'value': "'xml'"}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'string', 'children': [], 'value': "'utf8'"}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '234']}, {'id': '229', 'type': 'subscript', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': '_dbus_class_table'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'orig_interfaces'}, {'id': '235', 'type': 'return_statement', 'children': ['236']} | def Introspect(self, object_path, connection):
'''Return XML description of this object's interfaces, methods and signals.
This wraps dbus-python's Introspect() method to include the dynamic
methods and properties.
'''
cls = self.__class__.__module__ + '.' + self.__class__.__name__
orig_interfaces = self._dbus_class_table[cls]
mock_interfaces = orig_interfaces.copy()
for interface, methods in self.methods.items():
for method in methods:
mock_interfaces.setdefault(interface, {})[method] = self.methods[interface][method][3]
self._dbus_class_table[cls] = mock_interfaces
xml = dbus.service.Object.Introspect(self, object_path, connection)
tree = ElementTree.fromstring(xml)
for name in self.props:
interface = tree.find(".//interface[@name='%s']" % name)
if interface is None:
interface = ElementTree.Element("interface", {"name": name})
tree.append(interface)
for prop, val in self.props[name].items():
if val is None:
continue
elem = ElementTree.Element("property", {
"name": prop,
"type": dbus.lowlevel.Message.guess_signature(val),
"access": "readwrite"})
interface.append(elem)
xml = ElementTree.tostring(tree, encoding='utf8', method='xml').decode('utf8')
self._dbus_class_table[cls] = orig_interfaces
return xml |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'argument'}, {'id': '3', 'type': 'parameters', 'children': ['4', '6', '9']}; {'id': '4', 'type': 'list_splat_pattern', 'children': ['5']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'param_decls'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'argument'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '20', '25']}; {'id': '18', 'type': 'list_splat', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'param_decls'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '22', 'type': 'boolean_operator', 'children': ['23', '24'], 'value': 'or'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Argument'}, {'id': '25', 'type': 'dictionary_splat', 'children': ['26']} | def argument(*param_decls, cls=None, **attrs):
return click.argument(*param_decls, cls=cls or Argument, **attrs) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'option'}, {'id': '3', 'type': 'parameters', 'children': ['4', '6', '9']}; {'id': '4', 'type': 'list_splat_pattern', 'children': ['5']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'param_decls'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'option'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '20', '25']}; {'id': '18', 'type': 'list_splat', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'param_decls'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '22', 'type': 'boolean_operator', 'children': ['23', '24'], 'value': 'or'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Option'}, {'id': '25', 'type': 'dictionary_splat', 'children': ['26']} | def option(*param_decls, cls=None, **attrs):
return click.option(*param_decls, cls=cls or Option, **attrs) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_to_loader_class'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'loader_class'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '13', 'type': 'block', 'children': ['14', '23', '31', '41', '55', '63', '101']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '22', 'type': 'string', 'children': [], 'value': "''"}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '30', 'type': 'argument_list', 'children': []}, {'id': '31', 'type': 'if_statement', 'children': ['32', '34']}; {'id': '32', 'type': 'not_operator', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'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': 'tag'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'DEFAULT_TAG_NAME'}, {'id': '41', 'type': 'if_statement', 'children': ['42', '49']}; {'id': '42', 'type': 'not_operator', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'!'"}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'raise_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'string', 'children': [], 'value': '\'`tag` argument should start with character "!"\''}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'dictionary_splat', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '63', 'type': 'if_statement', 'children': ['64', '67', '90']}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '66'], 'value': 'is'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'loader_class'}; {'id': '66', 'type': 'None', 'children': []}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'if_statement', 'children': ['69', '70', '80']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'FullLoader'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'yaml'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'add_constructor'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'FullLoader'}; {'id': '80', 'type': 'else_clause', 'children': ['81']}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'yaml'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'add_constructor'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '90', 'type': 'else_clause', 'children': ['91']}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'yaml'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'add_constructor'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99', '100']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'loader_class'}, {'id': '101', 'type': 'return_statement', 'children': ['102']} | def add_to_loader_class(cls, loader_class=None, tag=None, **kwargs):
if tag is None:
tag = ''
tag = tag.strip()
if not tag:
tag = cls.DEFAULT_TAG_NAME
if not tag.startswith('!'):
raise ValueError('`tag` argument should start with character "!"')
instance = cls(**kwargs)
if loader_class is None:
if FullLoader:
yaml.add_constructor(tag, instance, FullLoader)
else:
yaml.add_constructor(tag, instance)
else:
yaml.add_constructor(tag, instance, loader_class)
return instance |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26', '28']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_table'}, {'id': '3', 'type': 'parameters', 'children': ['4', '8', '12', '21']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'column_names'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'IterableOfStrings'}; {'id': '8', 'type': 'typed_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'IterableOfTuples'}; {'id': '12', 'type': 'typed_default_parameter', 'children': ['13', '14', '20']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'column_alignments'}; {'id': '14', 'type': 'type', 'children': ['15']}, {'id': '15', 'type': 'generic_type', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'Optional'}, {'id': '17', 'type': 'type_parameter', 'children': ['18']}; {'id': '18', 'type': 'type', 'children': ['19']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'IterableOfStrings'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'typed_default_parameter', 'children': ['22', '23', '25']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'primary_column_idx'}, {'id': '23', 'type': 'type', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'type', 'children': ['27']}, {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29', '33', '37', '41', '54', '73', '83', '105', '145', '208']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'header_template'}; {'id': '32', 'type': 'string', 'children': [], 'value': "''"}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'row_template'}; {'id': '36', 'type': 'string', 'children': [], 'value': "''"}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'table_width'}; {'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': 'type_formatters'}; {'id': '44', 'type': 'dictionary', 'children': ['45', '48', '51']}, {'id': '45', 'type': 'pair', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '47', 'type': 'string', 'children': [], 'value': "'d'"}; {'id': '48', 'type': 'pair', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'f'"}, {'id': '51', 'type': 'pair', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'s'"}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'types'}, {'id': '57', 'type': 'list_comprehension', 'children': ['58', '68']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'type_formatters'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '67']}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '67', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'alignments'}; {'id': '76', 'type': 'dictionary', 'children': ['77', '80']}, {'id': '77', 'type': 'pair', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '79', 'type': 'string', 'children': [], 'value': "'>'"}; {'id': '80', 'type': 'pair', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'>'"}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'column_alignments'}; {'id': '86', 'type': 'parenthesized_expression', 'children': ['87'], 'value': '()'}, {'id': '87', 'type': 'boolean_operator', 'children': ['88', '89'], 'value': 'or'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'column_alignments'}, {'id': '89', 'type': 'list_comprehension', 'children': ['90', '100']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'alignments'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '99']}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '99', 'type': 'string', 'children': [], 'value': "'<'"}; {'id': '100', 'type': 'for_in_clause', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '105', 'type': 'function_definition', 'children': ['106', '107', '109']}; {'id': '106', 'type': 'function_name', 'children': [], 'value': 'get_column_width'}, {'id': '107', 'type': 'parameters', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '109', 'type': 'block', 'children': ['110', '119', '137']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'header_length'}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'column_names'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'content_length'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '124', 'type': 'generator_expression', 'children': ['125', '134']}, {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '134', 'type': 'for_in_clause', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'rows'}, {'id': '137', 'type': 'return_statement', 'children': ['138']}; {'id': '138', 'type': 'parenthesized_expression', 'children': ['139'], 'value': '()'}, {'id': '139', 'type': 'conditional_expression', 'children': ['140', '141', '144'], 'value': 'if'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'content_length'}, {'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': '>'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'content_length'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'header_length'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'header_length'}, {'id': '145', 'type': 'for_statement', 'children': ['146', '147', '155']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '149', 'type': 'argument_list', 'children': ['150', '151']}; {'id': '150', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '151', 'type': 'call', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'column_names'}, {'id': '155', 'type': 'block', 'children': ['156', '163', '167', '171']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'col_width'}, {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'get_column_width'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'header_col_template'}; {'id': '166', 'type': 'string', 'children': [], 'value': "f'{{:{col_width}}}'"}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'col_template'}; {'id': '170', 'type': 'string', 'children': [], 'value': "f'{{:{column_alignments[i]}{col_width}{types[i]}}}'"}, {'id': '171', 'type': 'if_statement', 'children': ['172', '175', '188']}; {'id': '172', 'type': 'comparison_operator', 'children': ['173', '174'], 'value': '=='}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '174', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '175', 'type': 'block', 'children': ['176', '180', '184']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'augmented_assignment', 'children': ['178', '179'], 'value': '+='}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'header_template'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'header_col_template'}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'augmented_assignment', 'children': ['182', '183'], 'value': '+='}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'row_template'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'col_template'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'augmented_assignment', 'children': ['186', '187'], 'value': '+='}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'table_width'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'col_width'}; {'id': '188', 'type': 'else_clause', 'children': ['189']}, {'id': '189', 'type': 'block', 'children': ['190', '196', '202']}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'augmented_assignment', 'children': ['192', '193'], 'value': '+='}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'header_template'}, {'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '+'}; {'id': '194', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'header_col_template'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'augmented_assignment', 'children': ['198', '199'], 'value': '+='}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'row_template'}, {'id': '199', 'type': 'binary_operator', 'children': ['200', '201'], 'value': '+'}; {'id': '200', 'type': 'string', 'children': [], 'value': "' '"}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'col_template'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'augmented_assignment', 'children': ['204', '205'], 'value': '+='}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'table_width'}, {'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '+'}; {'id': '206', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'col_width'}; {'id': '208', 'type': 'if_statement', 'children': ['209', '214', '267']}, {'id': '209', 'type': 'comparison_operator', 'children': ['210', '211'], 'value': '<'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'table_width'}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'get_terminal_width'}, {'id': '213', 'type': 'argument_list', 'children': []}; {'id': '214', 'type': 'block', 'children': ['215', '228', '237']}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'call', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'click'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'call', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'header_template'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'list_splat', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'column_names'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'call', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'click'}; {'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': "'-'"}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'table_width'}, {'id': '237', 'type': 'for_statement', 'children': ['238', '239', '240']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '240', 'type': 'block', 'children': ['241']}, {'id': '241', 'type': 'try_statement', 'children': ['242', '256']}; {'id': '242', 'type': 'block', 'children': ['243']}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'click'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}, {'id': '249', 'type': 'call', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'row_template'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'list_splat', 'children': ['255']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '256', 'type': 'except_clause', 'children': ['257', '261']}, {'id': '257', 'type': 'as_pattern', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '259', 'type': 'as_pattern_target', 'children': ['260']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'e'}, {'id': '261', 'type': 'block', 'children': ['262']}; {'id': '262', 'type': 'raise_statement', 'children': ['263']}, {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'string', 'children': [], 'value': "f'{e}: {row!r}'"}, {'id': '267', 'type': 'else_clause', 'children': ['268']}; {'id': '268', 'type': 'block', 'children': ['269', '284', '303']}, {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'assignment', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'max_label_width'}; {'id': '272', 'type': 'call', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}, {'id': '275', 'type': 'list_splat', 'children': ['276']}; {'id': '276', 'type': 'list_comprehension', 'children': ['277', '281']}, {'id': '277', 'type': 'call', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '281', 'type': 'for_in_clause', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'label'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'column_names'}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'assignment', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'non_primary_columns'}, {'id': '287', 'type': 'list_comprehension', 'children': ['288', '291', '299']}; {'id': '288', 'type': 'tuple', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '291', 'type': 'for_in_clause', 'children': ['292', '295']}; {'id': '292', 'type': 'pattern_list', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '295', 'type': 'call', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'column_names'}, {'id': '299', 'type': 'if_clause', 'children': ['300']}; {'id': '300', 'type': 'comparison_operator', 'children': ['301', '302'], 'value': '!='}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'primary_column_idx'}, {'id': '303', 'type': 'for_statement', 'children': ['304', '305', '306']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '306', 'type': 'block', 'children': ['307', '313', '317', '334', '359']}, {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'assignment', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'type_'}; {'id': '310', 'type': 'subscript', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'types'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'primary_column_idx'}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'assignment', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'row_template'}; {'id': '316', 'type': 'string', 'children': [], 'value': "f'{{:>{max_label_width}s}}: {{:{type_}}}'"}, {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '322']}, {'id': '319', 'type': 'attribute', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'click'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'echo'}; {'id': '322', 'type': 'argument_list', 'children': ['323']}, {'id': '323', 'type': 'call', 'children': ['324', '327']}; {'id': '324', 'type': 'attribute', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'row_template'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '327', 'type': 'argument_list', 'children': ['328', '331']}; {'id': '328', 'type': 'subscript', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'column_names'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'primary_column_idx'}, {'id': '331', 'type': 'subscript', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'primary_column_idx'}; {'id': '334', 'type': 'for_statement', 'children': ['335', '338', '339']}, {'id': '335', 'type': 'pattern_list', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'non_primary_columns'}, {'id': '339', 'type': 'block', 'children': ['340', '344']}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}, {'id': '341', 'type': 'assignment', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'row_template'}, {'id': '343', 'type': 'string', 'children': [], 'value': "f'{{:>{max_label_width}s}}: {{:{types[i]}}}'"}; {'id': '344', 'type': 'expression_statement', 'children': ['345']}, {'id': '345', 'type': 'call', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'click'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'echo'}, {'id': '349', 'type': 'argument_list', 'children': ['350']}; {'id': '350', 'type': 'call', 'children': ['351', '354']}, {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'row_template'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '354', 'type': 'argument_list', 'children': ['355', '356']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '356', 'type': 'subscript', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '359', 'type': 'expression_statement', 'children': ['360']}; {'id': '360', 'type': 'call', 'children': ['361', '364']}, {'id': '361', 'type': 'attribute', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'click'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'echo'} | def print_table(column_names: IterableOfStrings,
rows: IterableOfTuples,
column_alignments: Optional[IterableOfStrings] = None,
primary_column_idx: int = 0,
) -> None:
header_template = ''
row_template = ''
table_width = 0
type_formatters = {int: 'd', float: 'f', str: 's'}
types = [type_formatters.get(type(x), 'r') for x in rows[0]]
alignments = {int: '>', float: '>'}
column_alignments = (column_alignments or
[alignments.get(type(x), '<') for x in rows[0]])
def get_column_width(idx):
header_length = len(column_names[idx])
content_length = max(len(str(row[idx])) for row in rows)
return (content_length if content_length > header_length
else header_length)
for i in range(0, len(column_names)):
col_width = get_column_width(i)
header_col_template = f'{{:{col_width}}}'
col_template = f'{{:{column_alignments[i]}{col_width}{types[i]}}}'
if i == 0:
header_template += header_col_template
row_template += col_template
table_width += col_width
else:
header_template += ' ' + header_col_template
row_template += ' ' + col_template
table_width += 2 + col_width
if table_width < get_terminal_width():
click.echo(header_template.format(*column_names))
click.echo('-' * table_width)
for row in rows:
try:
click.echo(row_template.format(*row))
except TypeError as e:
raise TypeError(f'{e}: {row!r}')
else:
max_label_width = max(*[len(label) for label in column_names])
non_primary_columns = [(i, col) for i, col in enumerate(column_names)
if i != primary_column_idx]
for row in rows:
type_ = types[primary_column_idx]
row_template = f'{{:>{max_label_width}s}}: {{:{type_}}}'
click.echo(row_template.format(column_names[primary_column_idx],
row[primary_column_idx]))
for i, label in non_primary_columns:
row_template = f'{{:>{max_label_width}s}}: {{:{types[i]}}}'
click.echo(row_template.format(label, row[i]))
click.echo() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'model_fields'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'db_session'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'only'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'field_args'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'converter'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'exclude_fk'}, {'id': '25', 'type': 'False', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '35', '43', '49', '53', '102', '138', '142', '177']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': '_sa_class_manager'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'mapper'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '40'], 'value': 'or'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '_ModelConverter'}; {'id': '42', 'type': 'argument_list', 'children': []}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'field_args'}; {'id': '46', 'type': 'boolean_operator', 'children': ['47', '48'], 'value': 'or'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'field_args'}; {'id': '48', 'type': 'dictionary', 'children': []}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '52', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '53', 'type': 'for_statement', 'children': ['54', '55', '58']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'mapper'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'iterate_properties'}; {'id': '58', 'type': 'block', 'children': ['59', '91']}, {'id': '59', 'type': 'if_statement', 'children': ['60', '66']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64', '65']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '64', 'type': 'string', 'children': [], 'value': "'columns'"}, {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'if_statement', 'children': ['68', '77', '79']}; {'id': '68', 'type': 'boolean_operator', 'children': ['69', '70'], 'value': 'and'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'exclude_fk'}; {'id': '70', 'type': 'attribute', 'children': ['71', '76']}, {'id': '71', 'type': 'subscript', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'foreign_keys'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'continue_statement', 'children': []}, {'id': '79', 'type': 'elif_clause', 'children': ['80', '89']}; {'id': '80', 'type': 'boolean_operator', 'children': ['81', '82'], 'value': 'and'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'exclude_pk'}; {'id': '82', 'type': 'attribute', 'children': ['83', '88']}, {'id': '83', 'type': 'subscript', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '87', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'primary_key'}, {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'continue_statement', 'children': []}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'tuple', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '102', 'type': 'if_statement', 'children': ['103', '106', '121']}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'only'}, {'id': '105', 'type': 'None', 'children': []}; {'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': 'properties'}; {'id': '110', 'type': 'generator_expression', 'children': ['111', '112', '115']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '115', 'type': 'if_clause', 'children': ['116']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '120'], 'value': 'in'}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'only'}, {'id': '121', 'type': 'elif_clause', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'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': 'properties'}, {'id': '127', 'type': 'generator_expression', 'children': ['128', '129', '132']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '129', 'type': 'for_in_clause', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '132', 'type': 'if_clause', 'children': ['133']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '137'], 'value': 'not'}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'field_dict'}, {'id': '141', 'type': 'dictionary', 'children': []}; {'id': '142', 'type': 'for_statement', 'children': ['143', '146', '147']}, {'id': '143', 'type': 'pattern_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '147', 'type': 'block', 'children': ['148', '166']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'converter'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'convert'}, {'id': '155', 'type': 'argument_list', 'children': ['156', '157', '158', '159', '165']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'model'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'mapper'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'field_args'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'db_session'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '170']}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': 'is'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '169', 'type': 'None', 'children': []}; {'id': '170', 'type': 'block', 'children': ['171']}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '176']}, {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'field_dict'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '177', 'type': 'return_statement', 'children': ['178']} | def model_fields(model, db_session=None, only=None, exclude=None,
field_args=None, converter=None, exclude_pk=False,
exclude_fk=False):
mapper = model._sa_class_manager.mapper
converter = converter or _ModelConverter()
field_args = field_args or {}
properties = []
for prop in mapper.iterate_properties:
if getattr(prop, 'columns', None):
if exclude_fk and prop.columns[0].foreign_keys:
continue
elif exclude_pk and prop.columns[0].primary_key:
continue
properties.append((prop.key, prop))
if only is not None:
properties = (x for x in properties if x[0] in only)
elif exclude:
properties = (x for x in properties if x[0] not in exclude)
field_dict = {}
for name, prop in properties:
field = converter.convert(
model, mapper, prop,
field_args.get(name), db_session
)
if field is not None:
field_dict[name] = field
return field_dict |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'singularize'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'word'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'NOUN'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'custom'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '23', '73', '93', '101', '115', '129', '150', '177', '249']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '18']}, {'id': '13', 'type': 'boolean_operator', 'children': ['14', '15'], 'value': 'and'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'custom'}, {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'in'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'word'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'custom'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'subscript', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'custom'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'word'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '27']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'in'}, {'id': '25', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'word'}, {'id': '27', 'type': 'block', 'children': ['28', '37']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'word'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': '"-"'}, {'id': '37', 'type': 'if_statement', 'children': ['38', '50']}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '45'], 'value': 'and'}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '44'], 'value': '>'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '44', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '49'], 'value': 'in'}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'plural_prepositions'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'binary_operator', 'children': ['53', '63'], 'value': '+'}, {'id': '53', 'type': 'binary_operator', 'children': ['54', '62'], 'value': '+'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'singularize'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '60', '61']}, {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '59', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'pos'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'custom'}; {'id': '62', 'type': 'string', 'children': [], 'value': '"-"'}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'string', 'children': [], 'value': '"-"'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '70', 'type': 'slice', 'children': ['71', '72']}, {'id': '71', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '72', 'type': 'colon', 'children': []}, {'id': '73', 'type': 'if_statement', 'children': ['74', '80']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'word'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'string', 'children': [], 'value': '"\'"'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'return_statement', 'children': ['82']}; {'id': '82', 'type': 'binary_operator', 'children': ['83', '92'], 'value': '+'}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'singularize'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'word'}; {'id': '88', 'type': 'slice', 'children': ['89', '90']}, {'id': '89', 'type': 'colon', 'children': []}; {'id': '90', 'type': 'unary_operator', 'children': ['91'], 'value': '-'}, {'id': '91', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '92', 'type': 'string', 'children': [], 'value': '"\'s"'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'word'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '100', 'type': 'argument_list', 'children': []}, {'id': '101', 'type': 'for_statement', 'children': ['102', '103', '104']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'singular_uninflected'}; {'id': '104', 'type': 'block', 'children': ['105']}, {'id': '105', 'type': 'if_statement', 'children': ['106', '112']}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'return_statement', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'word'}, {'id': '115', 'type': 'for_statement', 'children': ['116', '117', '118']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'singular_uncountable'}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'if_statement', 'children': ['120', '126']}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'return_statement', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'word'}, {'id': '129', 'type': 'for_statement', 'children': ['130', '131', '132']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'singular_ie'}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'if_statement', 'children': ['134', '142']}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'binary_operator', 'children': ['140', '141'], 'value': '+'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '141', 'type': 'string', 'children': [], 'value': '"s"'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'return_statement', 'children': ['144']}; {'id': '144', 'type': 'subscript', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '146', 'type': 'slice', 'children': ['147', '148']}, {'id': '147', 'type': 'colon', 'children': []}; {'id': '148', 'type': 'unary_operator', 'children': ['149'], 'value': '-'}, {'id': '149', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '150', 'type': 'for_statement', 'children': ['151', '152', '153']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'singular_irregular'}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'if_statement', 'children': ['155', '161']}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'endswith'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'return_statement', 'children': ['163']}, {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '167', 'type': 'argument_list', 'children': ['168', '173', '176']}; {'id': '168', 'type': 'binary_operator', 'children': ['169', '172'], 'value': '+'}, {'id': '169', 'type': 'binary_operator', 'children': ['170', '171'], 'value': '+'}; {'id': '170', 'type': 'string', 'children': [], 'value': "'(?i)'"}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '172', 'type': 'string', 'children': [], 'value': "'$'"}, {'id': '173', 'type': 'subscript', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'singular_irregular'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'word'}, {'id': '177', 'type': 'for_statement', 'children': ['178', '181', '182']}; {'id': '178', 'type': 'pattern_list', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'inflection'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'singular_rules'}; {'id': '182', 'type': 'block', 'children': ['183', '192', '204']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'word'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '195', 'type': 'boolean_operator', 'children': ['196', '203'], 'value': 'or'}; {'id': '196', 'type': 'boolean_operator', 'children': ['197', '198'], 'value': 'and'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '202', 'type': 'argument_list', 'children': []}, {'id': '203', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '204', 'type': 'if_statement', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '206', 'type': 'block', 'children': ['207', '241']}, {'id': '207', 'type': 'for_statement', 'children': ['208', '209', '216']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '216', 'type': 'block', 'children': ['217']}, {'id': '217', 'type': 'if_statement', 'children': ['218', '223']}; {'id': '218', 'type': 'comparison_operator', 'children': ['219', '222'], 'value': 'is'}, {'id': '219', 'type': 'subscript', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'g'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '222', 'type': 'None', 'children': []}, {'id': '223', 'type': 'block', 'children': ['224']}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}, {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'inflection'}, {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'inflection'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '231', 'type': 'argument_list', 'children': ['232', '240']}; {'id': '232', 'type': 'binary_operator', 'children': ['233', '234'], 'value': '+'}, {'id': '233', 'type': 'string', 'children': [], 'value': "'\\\\'"}; {'id': '234', 'type': 'call', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}, {'id': '237', 'type': 'binary_operator', 'children': ['238', '239'], 'value': '+'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'k'}, {'id': '239', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '240', 'type': 'string', 'children': [], 'value': "''"}, {'id': '241', 'type': 'return_statement', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '246']}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'suffix'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '246', 'type': 'argument_list', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'inflection'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'word'}, {'id': '249', 'type': 'return_statement', 'children': ['250']} | def singularize(word, pos=NOUN, custom=None):
if custom and word in custom:
return custom[word]
if "-" in word:
w = word.split("-")
if len(w) > 1 and w[1] in plural_prepositions:
return singularize(w[0], pos, custom) + "-" + "-".join(w[1:])
if word.endswith("'"):
return singularize(word[:-1]) + "'s"
w = word.lower()
for x in singular_uninflected:
if x.endswith(w):
return word
for x in singular_uncountable:
if x.endswith(w):
return word
for x in singular_ie:
if w.endswith(x + "s"):
return w[:-1]
for x in singular_irregular:
if w.endswith(x):
return re.sub('(?i)' + x + '$', singular_irregular[x], word)
for suffix, inflection in singular_rules:
m = suffix.search(word)
g = m and m.groups() or []
if m:
for k in range(len(g)):
if g[k] is None:
inflection = inflection.replace('\\' + str(k + 1), '')
return suffix.sub(inflection, word)
return word |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '37', '39']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'login_user'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '18', '27', '32']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'User'}, {'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '17']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'remember'}, {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'generic_type', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '14', 'type': 'type_parameter', 'children': ['15']}, {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'typed_default_parameter', 'children': ['19', '20', '26']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'duration'}; {'id': '20', 'type': 'type', 'children': ['21']}, {'id': '21', 'type': 'generic_type', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Optional'}, {'id': '23', 'type': 'type_parameter', 'children': ['24']}; {'id': '24', 'type': 'type', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'timedelta'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'typed_default_parameter', 'children': ['28', '29', '31']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'force'}, {'id': '29', 'type': 'type', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '31', 'type': 'False', 'children': []}; {'id': '32', 'type': 'typed_default_parameter', 'children': ['33', '34', '36']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'fresh'}; {'id': '34', 'type': 'type', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '36', 'type': 'True', 'children': []}, {'id': '37', 'type': 'type', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '39', 'type': 'block', 'children': ['40', '100', '114', '120', '132', '145', '186', '194', '208', '227']}; {'id': '40', 'type': 'if_statement', 'children': ['41', '43']}, {'id': '41', 'type': 'not_operator', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'force'}, {'id': '43', 'type': 'block', 'children': ['44', '58', '86']}; {'id': '44', 'type': 'if_statement', 'children': ['45', '49']}, {'id': '45', 'type': 'not_operator', 'children': ['46']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'active'}, {'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': 'AuthenticationError'}, {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'string', 'children': [], 'value': "'flask_unchained.bundles.security:error.disabled_account'"}; {'id': '58', 'type': 'if_statement', 'children': ['59', '77']}, {'id': '59', 'type': 'parenthesized_expression', 'children': ['60'], 'value': '()'}; {'id': '60', 'type': 'boolean_operator', 'children': ['61', '71'], 'value': 'and'}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '66'], 'value': 'and'}; {'id': '62', 'type': 'not_operator', 'children': ['63']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'confirmed_at'}; {'id': '66', 'type': 'attribute', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'security'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'confirmable'}, {'id': '71', 'type': 'not_operator', 'children': ['72']}; {'id': '72', 'type': 'attribute', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'security'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'login_without_confirmation'}, {'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': 'AuthenticationError'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'string', 'children': [], 'value': "'flask_unchained.bundles.security:error.confirmation_required'"}; {'id': '86', 'type': 'if_statement', 'children': ['87', '91']}, {'id': '87', 'type': 'not_operator', 'children': ['88']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'password'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'raise_statement', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'AuthenticationError'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'string', 'children': [], 'value': "'flask_unchained.bundles.security:error.password_not_set'"}; {'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': 'session'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'user_id'"}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '109', 'type': 'attribute', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'Meta'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'pk'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '119']}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '118', 'type': 'string', 'children': [], 'value': "'_fresh'"}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'fresh'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '125']}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '124', 'type': 'string', 'children': [], 'value': "'_id'"}, {'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': 'app'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'login_manager'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': '_session_identifier_generator'}, {'id': '131', 'type': 'argument_list', 'children': []}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'is'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'remember'}, {'id': '135', 'type': 'None', 'children': []}; {'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': 'remember'}; {'id': '140', 'type': 'attribute', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'SECURITY_DEFAULT_REMEMBER_ME'}, {'id': '145', 'type': 'if_statement', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'remember'}, {'id': '147', 'type': 'block', 'children': ['148', '154']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '153']}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'session'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'remember'"}, {'id': '153', 'type': 'string', 'children': [], 'value': "'set'"}; {'id': '154', 'type': 'if_statement', 'children': ['155', '158']}, {'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': 'is'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'duration'}, {'id': '157', 'type': 'None', 'children': []}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'try_statement', 'children': ['160', '171']}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '166']}, {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'session'}, {'id': '165', 'type': 'string', 'children': [], 'value': "'remember_seconds'"}; {'id': '166', 'type': 'call', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'duration'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'total_seconds'}; {'id': '170', 'type': 'argument_list', 'children': []}, {'id': '171', 'type': 'except_clause', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'raise_statement', 'children': ['175']}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '184']}, {'id': '179', 'type': 'attribute', 'children': ['180', '183']}; {'id': '180', 'type': 'concatenated_string', 'children': ['181', '182']}, {'id': '181', 'type': 'string', 'children': [], 'value': "'duration must be a datetime.timedelta, '"}; {'id': '182', 'type': 'string', 'children': [], 'value': "'instead got: {0}'"}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'duration'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '193']}; {'id': '188', 'type': 'attribute', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': '_request_ctx_stack'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'top'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'user_logged_in'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'send'}, {'id': '199', 'type': 'argument_list', 'children': ['200', '205']}; {'id': '200', 'type': 'call', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': '_get_current_object'}; {'id': '204', 'type': 'argument_list', 'children': []}, {'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'user'}; {'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': 'identity_changed'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'send'}, {'id': '213', 'type': 'argument_list', 'children': ['214', '219']}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': '_get_current_object'}; {'id': '218', 'type': 'argument_list', 'children': []}, {'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'identity'}, {'id': '221', 'type': 'call', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'Identity'}, {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'id'}, {'id': '227', 'type': 'return_statement', 'children': ['228']} | def login_user(self,
user: User,
remember: Optional[bool] = None,
duration: Optional[timedelta] = None,
force: bool = False,
fresh: bool = True,
) -> bool:
if not force:
if not user.active:
raise AuthenticationError(
_('flask_unchained.bundles.security:error.disabled_account'))
if (not user.confirmed_at
and self.security.confirmable
and not self.security.login_without_confirmation):
raise AuthenticationError(
_('flask_unchained.bundles.security:error.confirmation_required'))
if not user.password:
raise AuthenticationError(
_('flask_unchained.bundles.security:error.password_not_set'))
session['user_id'] = getattr(user, user.Meta.pk)
session['_fresh'] = fresh
session['_id'] = app.login_manager._session_identifier_generator()
if remember is None:
remember = app.config.SECURITY_DEFAULT_REMEMBER_ME
if remember:
session['remember'] = 'set'
if duration is not None:
try:
session['remember_seconds'] = duration.total_seconds()
except AttributeError:
raise Exception('duration must be a datetime.timedelta, '
'instead got: {0}'.format(duration))
_request_ctx_stack.top.user = user
user_logged_in.send(app._get_current_object(), user=user)
identity_changed.send(app._get_current_object(),
identity=Identity(user.id))
return True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '70', '78']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'url_for'}, {'id': '3', 'type': 'parameters', 'children': ['4', '8', '17', '32', '41', '50', '59', '68']}; {'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'endpoint_or_url_or_config_key'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '8', 'type': 'typed_default_parameter', 'children': ['9', '10', '16']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': '_anchor'}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'generic_type', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Optional'}, {'id': '13', 'type': 'type_parameter', 'children': ['14']}; {'id': '14', 'type': 'type', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'typed_default_parameter', 'children': ['18', '19', '31']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_cls'}, {'id': '19', 'type': 'type', 'children': ['20']}; {'id': '20', 'type': 'generic_type', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '22', 'type': 'type_parameter', 'children': ['23']}, {'id': '23', 'type': 'type', 'children': ['24']}; {'id': '24', 'type': 'generic_type', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'Union'}; {'id': '26', 'type': 'type_parameter', 'children': ['27', '29']}, {'id': '27', 'type': 'type', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'object'}, {'id': '29', 'type': 'type', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'typed_default_parameter', 'children': ['33', '34', '40']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': '_external'}; {'id': '34', 'type': 'type', 'children': ['35']}, {'id': '35', 'type': 'generic_type', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'Optional'}, {'id': '37', 'type': 'type_parameter', 'children': ['38']}; {'id': '38', 'type': 'type', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '40', 'type': 'False', 'children': []}, {'id': '41', 'type': 'typed_default_parameter', 'children': ['42', '43', '49']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': '_external_host'}, {'id': '43', 'type': 'type', 'children': ['44']}; {'id': '44', 'type': 'generic_type', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '46', 'type': 'type_parameter', 'children': ['47']}, {'id': '47', 'type': 'type', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'typed_default_parameter', 'children': ['51', '52', '58']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': '_method'}; {'id': '52', 'type': 'type', 'children': ['53']}, {'id': '53', 'type': 'generic_type', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'Optional'}, {'id': '55', 'type': 'type_parameter', 'children': ['56']}; {'id': '56', 'type': 'type', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '58', 'type': 'None', 'children': []}, {'id': '59', 'type': 'typed_default_parameter', 'children': ['60', '61', '67']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_scheme'}, {'id': '61', 'type': 'type', 'children': ['62']}; {'id': '62', 'type': 'generic_type', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '64', 'type': 'type_parameter', 'children': ['65']}, {'id': '65', 'type': 'type', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'dictionary_splat_pattern', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '70', 'type': 'type', 'children': ['71']}, {'id': '71', 'type': 'generic_type', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'Union'}, {'id': '73', 'type': 'type_parameter', 'children': ['74', '76']}; {'id': '74', 'type': 'type', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '76', 'type': 'type', 'children': ['77']}, {'id': '77', 'type': 'None', 'children': []}; {'id': '78', 'type': 'block', 'children': ['79', '83', '103', '118', '128', '151', '195']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'what'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'endpoint_or_url_or_config_key'}, {'id': '83', 'type': 'if_statement', 'children': ['84', '91']}; {'id': '84', 'type': 'boolean_operator', 'children': ['85', '86'], 'value': 'and'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'what'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'what'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'isupper'}; {'id': '90', 'type': 'argument_list', 'children': []}, {'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': 'what'}, {'id': '95', 'type': 'call', 'children': ['96', '101']}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'current_app'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'what'}, {'id': '103', 'type': 'if_statement', 'children': ['104', '109']}; {'id': '104', 'type': 'call', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'what'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'LocalProxy'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'what'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'what'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': '_get_current_object'}, {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'if_statement', 'children': ['119', '125']}, {'id': '119', 'type': 'boolean_operator', 'children': ['120', '122'], 'value': 'or'}; {'id': '120', 'type': 'not_operator', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'what'}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'in'}, {'id': '123', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'what'}, {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'return_statement', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'what'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'flask_url_for_kwargs'}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '133', 'type': 'argument_list', 'children': ['134', '137', '140', '143', '146', '149']}; {'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': '_anchor'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': '_anchor'}, {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': '_external'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': '_external'}; {'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': '_external_host'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': '_external_host'}, {'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': '_method'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': '_method'}; {'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': '_scheme'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '_scheme'}, {'id': '149', 'type': 'dictionary_splat', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '151', 'type': 'if_statement', 'children': ['152', '157']}; {'id': '152', 'type': 'boolean_operator', 'children': ['153', '154'], 'value': 'and'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': '_cls'}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': 'not'}, {'id': '155', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'what'}, {'id': '157', 'type': 'block', 'children': ['158', '166', '175']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'controller_routes'}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '163', 'type': 'argument_list', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': '_cls'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'CONTROLLER_ROUTES_ATTR'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'method_routes'}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'controller_routes'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'what'}, {'id': '175', 'type': 'try_statement', 'children': ['176', '188']}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'return_statement', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': '_url_for'}; {'id': '180', 'type': 'argument_list', 'children': ['181', '186']}, {'id': '181', 'type': 'attribute', 'children': ['182', '185']}; {'id': '182', 'type': 'subscript', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'method_routes'}; {'id': '184', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'endpoint'}; {'id': '186', 'type': 'dictionary_splat', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'flask_url_for_kwargs'}; {'id': '188', 'type': 'except_clause', 'children': ['189', '193']}, {'id': '189', 'type': 'tuple', 'children': ['190', '191', '192']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'BuildError'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'TypeError'}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'pass_statement', 'children': []}, {'id': '195', 'type': 'return_statement', 'children': ['196']}; {'id': '196', 'type': 'call', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': '_url_for'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'what'}; {'id': '200', 'type': 'dictionary_splat', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'flask_url_for_kwargs'} | def url_for(endpoint_or_url_or_config_key: str,
_anchor: Optional[str] = None,
_cls: Optional[Union[object, type]] = None,
_external: Optional[bool] = False,
_external_host: Optional[str] = None,
_method: Optional[str] = None,
_scheme: Optional[str] = None,
**values,
) -> Union[str, None]:
what = endpoint_or_url_or_config_key
if what and what.isupper():
what = current_app.config.get(what)
if isinstance(what, LocalProxy):
what = what._get_current_object()
if not what or '/' in what:
return what
flask_url_for_kwargs = dict(_anchor=_anchor, _external=_external,
_external_host=_external_host, _method=_method,
_scheme=_scheme, **values)
if _cls and '.' not in what:
controller_routes = getattr(_cls, CONTROLLER_ROUTES_ATTR)
method_routes = controller_routes.get(what)
try:
return _url_for(method_routes[0].endpoint, **flask_url_for_kwargs)
except (
BuildError,
IndexError,
TypeError,
):
pass
return _url_for(what, **flask_url_for_kwargs) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '93', '95']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'redirect'}, {'id': '3', 'type': 'parameters', 'children': ['4', '13', '22', '31', '40', '55', '64', '73', '82', '91']}; {'id': '4', 'type': 'typed_default_parameter', 'children': ['5', '6', '12']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '6', 'type': 'type', 'children': ['7']}, {'id': '7', 'type': 'generic_type', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'Optional'}, {'id': '9', 'type': 'type_parameter', 'children': ['10']}; {'id': '10', 'type': 'type', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'typed_default_parameter', 'children': ['14', '15', '21']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '15', 'type': 'type', 'children': ['16']}; {'id': '16', 'type': 'generic_type', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '18', 'type': 'type_parameter', 'children': ['19']}, {'id': '19', 'type': 'type', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '21', 'type': 'None', 'children': []}; {'id': '22', 'type': 'typed_default_parameter', 'children': ['23', '24', '30']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'override'}; {'id': '24', 'type': 'type', 'children': ['25']}, {'id': '25', 'type': 'generic_type', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'Optional'}, {'id': '27', 'type': 'type_parameter', 'children': ['28']}; {'id': '28', 'type': 'type', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'typed_default_parameter', 'children': ['32', '33', '39']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_anchor'}, {'id': '33', 'type': 'type', 'children': ['34']}; {'id': '34', 'type': 'generic_type', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '36', 'type': 'type_parameter', 'children': ['37']}, {'id': '37', 'type': 'type', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'typed_default_parameter', 'children': ['41', '42', '54']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': '_cls'}; {'id': '42', 'type': 'type', 'children': ['43']}, {'id': '43', 'type': 'generic_type', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'Optional'}, {'id': '45', 'type': 'type_parameter', 'children': ['46']}; {'id': '46', 'type': 'type', 'children': ['47']}, {'id': '47', 'type': 'generic_type', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'Union'}, {'id': '49', 'type': 'type_parameter', 'children': ['50', '52']}; {'id': '50', 'type': 'type', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'object'}; {'id': '52', 'type': 'type', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '54', 'type': 'None', 'children': []}, {'id': '55', 'type': 'typed_default_parameter', 'children': ['56', '57', '63']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_external'}, {'id': '57', 'type': 'type', 'children': ['58']}; {'id': '58', 'type': 'generic_type', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '60', 'type': 'type_parameter', 'children': ['61']}, {'id': '61', 'type': 'type', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '63', 'type': 'False', 'children': []}; {'id': '64', 'type': 'typed_default_parameter', 'children': ['65', '66', '72']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': '_external_host'}; {'id': '66', 'type': 'type', 'children': ['67']}, {'id': '67', 'type': 'generic_type', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'Optional'}, {'id': '69', 'type': 'type_parameter', 'children': ['70']}; {'id': '70', 'type': 'type', 'children': ['71']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '72', 'type': 'None', 'children': []}, {'id': '73', 'type': 'typed_default_parameter', 'children': ['74', '75', '81']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_method'}, {'id': '75', 'type': 'type', 'children': ['76']}; {'id': '76', 'type': 'generic_type', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'Optional'}; {'id': '78', 'type': 'type_parameter', 'children': ['79']}, {'id': '79', 'type': 'type', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '81', 'type': 'None', 'children': []}; {'id': '82', 'type': 'typed_default_parameter', 'children': ['83', '84', '90']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': '_scheme'}; {'id': '84', 'type': 'type', 'children': ['85']}, {'id': '85', 'type': 'generic_type', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'Optional'}, {'id': '87', 'type': 'type_parameter', 'children': ['88']}; {'id': '88', 'type': 'type', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '90', 'type': 'None', 'children': []}, {'id': '91', 'type': 'dictionary_splat_pattern', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '93', 'type': 'type', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'Response'}, {'id': '95', 'type': 'block', 'children': ['96', '119', '149', '167', '185', '204', '220']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'flask_url_for_kwargs'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'dict'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '105', '108', '111', '114', '117']}; {'id': '102', 'type': 'keyword_argument', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': '_anchor'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': '_anchor'}, {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': '_external'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': '_external'}; {'id': '108', 'type': 'keyword_argument', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': '_external_host'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': '_external_host'}, {'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': '_method'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': '_method'}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': '_scheme'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': '_scheme'}, {'id': '117', 'type': 'dictionary_splat', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'urls'}; {'id': '122', 'type': 'list', 'children': ['123', '136'], 'value': "[url_for(request.args.get('next'), **flask_url_for_kwargs),\n url_for(request.form.get('next'), **flask_url_for_kwargs)]"}, {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'url_for'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '134']}; {'id': '126', 'type': 'call', 'children': ['127', '132']}, {'id': '127', 'type': 'attribute', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'request'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'string', 'children': [], 'value': "'next'"}; {'id': '134', 'type': 'dictionary_splat', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'flask_url_for_kwargs'}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'url_for'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '147']}, {'id': '139', 'type': 'call', 'children': ['140', '145']}; {'id': '140', 'type': 'attribute', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'form'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'string', 'children': [], 'value': "'next'"}, {'id': '147', 'type': 'dictionary_splat', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'flask_url_for_kwargs'}, {'id': '149', 'type': 'if_statement', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'where'}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'urls'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'url_for'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162', '165']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'where'}; {'id': '162', 'type': 'keyword_argument', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': '_cls'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': '_cls'}, {'id': '165', 'type': 'dictionary_splat', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'flask_url_for_kwargs'}, {'id': '167', 'type': 'if_statement', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'default'}, {'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': 'urls'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'url_for'}; {'id': '178', 'type': 'argument_list', 'children': ['179', '180', '183']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '180', 'type': 'keyword_argument', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': '_cls'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': '_cls'}, {'id': '183', 'type': 'dictionary_splat', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'flask_url_for_kwargs'}, {'id': '185', 'type': 'if_statement', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'override'}, {'id': '187', 'type': 'block', 'children': ['188']}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'urls'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'insert'}, {'id': '193', 'type': 'argument_list', 'children': ['194', '195']}; {'id': '194', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'url_for'}, {'id': '197', 'type': 'argument_list', 'children': ['198', '199', '202']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'override'}, {'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': '_cls'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': '_cls'}; {'id': '202', 'type': 'dictionary_splat', 'children': ['203']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'flask_url_for_kwargs'}; {'id': '204', 'type': 'for_statement', 'children': ['205', '206', '207']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'urls'}, {'id': '207', 'type': 'block', 'children': ['208']}; {'id': '208', 'type': 'if_statement', 'children': ['209', '214']}, {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': '_validate_redirect_url'}, {'id': '211', 'type': 'argument_list', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'url'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': '_external_host'}; {'id': '214', 'type': 'block', 'children': ['215']}, {'id': '215', 'type': 'return_statement', 'children': ['216']}; {'id': '216', 'type': 'call', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'flask_redirect'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '220', 'type': 'return_statement', 'children': ['221']}, {'id': '221', 'type': 'call', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'flask_redirect'}, {'id': '223', 'type': 'argument_list', 'children': ['224']} | def redirect(where: Optional[str] = None,
default: Optional[str] = None,
override: Optional[str] = None,
_anchor: Optional[str] = None,
_cls: Optional[Union[object, type]] = None,
_external: Optional[bool] = False,
_external_host: Optional[str] = None,
_method: Optional[str] = None,
_scheme: Optional[str] = None,
**values,
) -> Response:
flask_url_for_kwargs = dict(_anchor=_anchor, _external=_external,
_external_host=_external_host, _method=_method,
_scheme=_scheme, **values)
urls = [url_for(request.args.get('next'), **flask_url_for_kwargs),
url_for(request.form.get('next'), **flask_url_for_kwargs)]
if where:
urls.append(url_for(where, _cls=_cls, **flask_url_for_kwargs))
if default:
urls.append(url_for(default, _cls=_cls, **flask_url_for_kwargs))
if override:
urls.insert(0, url_for(override, _cls=_cls, **flask_url_for_kwargs))
for url in urls:
if _validate_redirect_url(url, _external_host):
return flask_redirect(url)
return flask_redirect('/') |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'auth_required'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'decorated_fn'}; {'id': '6', 'type': 'None', 'children': []}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'role_rules'}, {'id': '9', 'type': 'block', 'children': ['10', '14', '18', '76', '121', '134']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'required_roles'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'one_of_roles'}, {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '27']}, {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'parenthesized_expression', 'children': ['21'], 'value': '()'}, {'id': '21', 'type': 'boolean_operator', 'children': ['22', '23'], 'value': 'and'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'decorated_fn'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'callable'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'decorated_fn'}, {'id': '27', 'type': 'block', 'children': ['28', '65']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '36', '42', '54']}, {'id': '29', 'type': 'boolean_operator', 'children': ['30', '33'], 'value': 'and'}; {'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'in'}, {'id': '31', 'type': 'string', 'children': [], 'value': "'role'"}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'role_rules'}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'in'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'roles'"}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'role_rules'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'raise_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'string', 'children': [], 'value': "'specify only one of `role` or `roles` kwargs'"}; {'id': '42', 'type': 'elif_clause', 'children': ['43', '46']}, {'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'in'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'role'"}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'role_rules'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'required_roles'}; {'id': '50', 'type': 'list', 'children': ['51'], 'value': "[role_rules['role']]"}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'role_rules'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'role'"}; {'id': '54', 'type': 'elif_clause', 'children': ['55', '58']}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'in'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'roles'"}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'role_rules'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'required_roles'}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'role_rules'}; {'id': '64', 'type': 'string', 'children': [], 'value': "'roles'"}, {'id': '65', 'type': 'if_statement', 'children': ['66', '69']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'in'}, {'id': '67', 'type': 'string', 'children': [], 'value': "'one_of'"}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'role_rules'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'one_of_roles'}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'role_rules'}, {'id': '75', 'type': 'string', 'children': [], 'value': "'one_of'"}; {'id': '76', 'type': 'function_definition', 'children': ['77', '78', '80']}, {'id': '77', 'type': 'function_name', 'children': [], 'value': 'wrapper'}; {'id': '78', 'type': 'parameters', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '80', 'type': 'block', 'children': ['81', '119']}, {'id': '81', 'type': 'decorated_definition', 'children': ['82', '87', '91', '97', '103']}; {'id': '82', 'type': 'decorator', 'children': ['83']}, {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'wraps'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '87', 'type': 'decorator', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': '_auth_required'}; {'id': '90', 'type': 'argument_list', 'children': []}, {'id': '91', 'type': 'decorator', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'roles_required'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'list_splat', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'required_roles'}, {'id': '97', 'type': 'decorator', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'roles_accepted'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'list_splat', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'one_of_roles'}, {'id': '103', 'type': 'function_definition', 'children': ['104', '105', '110']}; {'id': '104', 'type': 'function_name', 'children': [], 'value': 'decorated'}, {'id': '105', 'type': 'parameters', 'children': ['106', '108']}; {'id': '106', 'type': 'list_splat_pattern', 'children': ['107']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '108', 'type': 'dictionary_splat_pattern', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'return_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'fn'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '117']}, {'id': '115', 'type': 'list_splat', 'children': ['116']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '117', 'type': 'dictionary_splat', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '119', 'type': 'return_statement', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'decorated'}, {'id': '121', 'type': 'if_statement', 'children': ['122', '128']}; {'id': '122', 'type': 'boolean_operator', 'children': ['123', '124'], 'value': 'and'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'decorated_fn'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'decorated_fn'}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'return_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'wrapper'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'decorated_fn'}; {'id': '134', 'type': 'return_statement', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'wrapper'} | def auth_required(decorated_fn=None, **role_rules):
required_roles = []
one_of_roles = []
if not (decorated_fn and callable(decorated_fn)):
if 'role' in role_rules and 'roles' in role_rules:
raise RuntimeError('specify only one of `role` or `roles` kwargs')
elif 'role' in role_rules:
required_roles = [role_rules['role']]
elif 'roles' in role_rules:
required_roles = role_rules['roles']
if 'one_of' in role_rules:
one_of_roles = role_rules['one_of']
def wrapper(fn):
@wraps(fn)
@_auth_required()
@roles_required(*required_roles)
@roles_accepted(*one_of_roles)
def decorated(*args, **kwargs):
return fn(*args, **kwargs)
return decorated
if decorated_fn and callable(decorated_fn):
return wrapper(decorated_fn)
return wrapper |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_tree'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '12', '24', '345']}; {'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': 'built'}; {'id': '10', 'type': 'block', 'children': ['11']}, {'id': '11', 'type': 'return_statement', 'children': []}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'doc_root'}, {'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': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '31']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'}; {'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': 'sorted_fields'}; {'id': '30', 'type': 'argument_list', 'children': []}, {'id': '31', 'type': 'block', 'children': ['32', '40', '48']}; {'id': '32', 'type': 'if_statement', 'children': ['33', '38']}, {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'not'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_fields'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'continue_statement', 'children': []}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '43', 'type': 'subscript', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '_fields'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '54']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': '!='}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'if_statement', 'children': ['56', '61', '99', '224', '281']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'XmlModel'}, {'id': '61', 'type': 'block', 'children': ['62', '68', '88']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'build_tree'}, {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'if_statement', 'children': ['69', '86']}, {'id': '69', 'type': 'parenthesized_expression', 'children': ['70'], 'value': '()'}; {'id': '70', 'type': 'boolean_operator', 'children': ['71', '78'], 'value': 'and'}, {'id': '71', 'type': 'boolean_operator', 'children': ['72', '75'], 'value': 'and'}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'drop_empty'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'drop_empty'}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '85'], 'value': '=='}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'doc_root'}, {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'continue_statement', 'children': []}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '95']}; {'id': '90', 'type': 'attribute', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'doc_root'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'doc_root'}, {'id': '99', 'type': 'elif_clause', 'children': ['100', '105']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '105', 'type': 'block', 'children': ['106']}; {'id': '106', 'type': 'for_statement', 'children': ['107', '108', '109']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '109', 'type': 'block', 'children': ['110', '220']}; {'id': '110', 'type': 'if_statement', 'children': ['111', '116', '147', '186']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'XmlField'}; {'id': '116', 'type': 'block', 'children': ['117', '125', '138']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'ele'}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '124', 'type': 'argument_list', 'children': []}, {'id': '125', 'type': 'if_statement', 'children': ['126', '136']}; {'id': '126', 'type': 'boolean_operator', 'children': ['127', '130'], 'value': 'and'}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'drop_empty'}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '135'], 'value': '=='}, {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ele'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'continue_statement', 'children': []}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'call', 'children': ['140', '145']}; {'id': '140', 'type': 'attribute', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'doc_root'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ele'}, {'id': '147', 'type': 'elif_clause', 'children': ['148', '153']}; {'id': '148', 'type': 'call', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '150', 'type': 'argument_list', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'XmlModel'}, {'id': '153', 'type': 'block', 'children': ['154', '160', '175']}; {'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': 'item'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'build_tree'}, {'id': '159', 'type': 'argument_list', 'children': []}; {'id': '160', 'type': 'if_statement', 'children': ['161', '173']}, {'id': '161', 'type': 'boolean_operator', 'children': ['162', '165'], 'value': 'and'}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'drop_empty'}, {'id': '165', 'type': 'comparison_operator', 'children': ['166', '172'], 'value': '=='}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'doc_root'}; {'id': '172', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'continue_statement', 'children': []}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '182']}, {'id': '177', 'type': 'attribute', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'doc_root'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'doc_root'}; {'id': '186', 'type': 'elif_clause', 'children': ['187', '198']}, {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '189', 'type': 'argument_list', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '191', 'type': 'tuple', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'text_type'}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'six'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'string_types'}; {'id': '198', 'type': 'block', 'children': ['199', '211']}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'ele'}; {'id': '202', 'type': 'call', 'children': ['203', '206']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'etree'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'fromstring'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'clean_xml'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '218']}, {'id': '213', 'type': 'attribute', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'doc_root'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '218', 'type': 'argument_list', 'children': ['219']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'ele'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '223', 'type': 'None', 'children': []}; {'id': '224', 'type': 'elif_clause', 'children': ['225', '241']}, {'id': '225', 'type': 'comparison_operator', 'children': ['226', '236'], 'value': '=='}; {'id': '226', 'type': 'parenthesized_expression', 'children': ['227'], 'value': '()'}, {'id': '227', 'type': 'boolean_operator', 'children': ['228', '231'], 'value': 'or'}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'parent'}, {'id': '231', 'type': 'attribute', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'name'}; {'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': 'root'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '241', 'type': 'block', 'children': ['242', '250', '268']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'ele'}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '249', 'type': 'argument_list', 'children': []}; {'id': '250', 'type': 'if_statement', 'children': ['251', '266']}, {'id': '251', 'type': 'boolean_operator', 'children': ['252', '262'], 'value': 'and'}; {'id': '252', 'type': 'boolean_operator', 'children': ['253', '256'], 'value': 'and'}, {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'drop_empty'}; {'id': '256', 'type': 'comparison_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': 'ele'}, {'id': '261', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '262', 'type': 'not_operator', 'children': ['263']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'ele'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '266', 'type': 'block', 'children': ['267']}, {'id': '267', 'type': 'continue_statement', 'children': []}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}, {'id': '269', 'type': 'assignment', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'ele'}, {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'doc_root'}, {'id': '281', 'type': 'else_clause', 'children': ['282']}; {'id': '282', 'type': 'block', 'children': ['283', '302']}, {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '286', 'type': 'list_comprehension', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '288', 'type': 'for_in_clause', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '290', 'type': 'call', 'children': ['291', '296']}, {'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': 'doc_root'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'iterdescendants'}; {'id': '296', 'type': 'argument_list', 'children': ['297']}, {'id': '297', 'type': 'keyword_argument', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'tag'}, {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '302', 'type': 'if_statement', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '304', 'type': 'block', 'children': ['305', '313', '332']}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'ele'}; {'id': '308', 'type': 'call', 'children': ['309', '312']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'field'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '312', 'type': 'argument_list', 'children': []}, {'id': '313', 'type': 'if_statement', 'children': ['314', '330']}; {'id': '314', 'type': 'parenthesized_expression', 'children': ['315'], 'value': '()'}, {'id': '315', 'type': 'boolean_operator', 'children': ['316', '326'], 'value': 'and'}; {'id': '316', 'type': 'boolean_operator', 'children': ['317', '320'], 'value': 'and'}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'drop_empty'}; {'id': '320', 'type': 'comparison_operator', 'children': ['321', '325'], 'value': '=='}, {'id': '321', 'type': 'call', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'ele'}, {'id': '325', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '326', 'type': 'not_operator', 'children': ['327']}, {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'ele'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '330', 'type': 'block', 'children': ['331']}, {'id': '331', 'type': 'continue_statement', 'children': []}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}, {'id': '333', 'type': 'assignment', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'ele'}, {'id': '335', 'type': 'call', 'children': ['336', '339']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'field'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '339', 'type': 'argument_list', 'children': ['340']}; {'id': '340', 'type': 'keyword_argument', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'parent'}; {'id': '342', 'type': 'subscript', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '344', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'assignment', 'children': ['347', '350']}, {'id': '347', 'type': 'attribute', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'built'} | def build_tree(self):
if self.built:
return
self.doc_root = self.root.element()
for key in self.sorted_fields():
if key not in self._fields:
continue
field = self._fields[key]
if field != self.root:
if isinstance(field, XmlModel):
field.build_tree()
if (self.drop_empty and field.drop_empty
and len(field.doc_root) == 0):
continue
self.doc_root.append(field.doc_root)
elif isinstance(field, list):
for item in field:
if isinstance(item, XmlField):
ele = item.element()
if self.drop_empty and len(ele) == 0:
continue
self.doc_root.append(ele)
elif isinstance(item, XmlModel):
item.build_tree()
if self.drop_empty and len(item.doc_root) == 0:
continue
self.doc_root.append(item.doc_root)
elif isinstance(item, (six.text_type, six.string_types)):
ele = etree.fromstring(clean_xml(item))
self.doc_root.append(ele)
item = None
elif (field.parent or self.root.name) == self.root.name:
ele = field.element()
if self.drop_empty and len(ele) == 0 and not ele.text:
continue
ele = field.element(parent=self.doc_root)
else:
nodes = [n for n in self.doc_root.iterdescendants(
tag=field.parent)]
if nodes:
ele = field.element()
if (self.drop_empty and len(ele) == 0 and not ele.text):
continue
ele = field.element(parent=nodes[0])
self.built = True |
Subsets and Splits