sequence
stringlengths 1.25k
34.6k
| code
stringlengths 75
8.58k
|
---|---|
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_item_sh'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'roles'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'date_field'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '17', '25', '34', '62', '71', '154', '158', '229']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '16', 'type': 'dictionary', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'author_field'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_field_author'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'if_statement', 'children': ['26', '28']},{'id': '26', 'type': 'not_operator', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'roles'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'roles'},{'id': '32', 'type': 'list', 'children': ['33'], 'value': '[author_field]'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'author_field'},{'id': '34', 'type': 'if_statement', 'children': ['35', '37', '51']},{'id': '35', 'type': 'not_operator', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'date_field'},{'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': 'item_date'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'str_to_datetime'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'item'},{'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': 'get_field_date'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'else_clause', 'children': ['52']},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'item_date'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'str_to_datetime'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'date_field'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'users_data'},{'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': 'get_users_data'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '71', 'type': 'for_statement', 'children': ['72', '73', '74']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'roles'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'if_statement', 'children': ['76', '79']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'in'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'users_data'},{'id': '79', 'type': 'block', 'children': ['80', '90', '106', '122', '138']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'get_sh_identity'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'get_item_sh_fields'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102', '103']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'item_date'},{'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '106', 'type': 'if_statement', 'children': ['107', '113']},{'id': '107', 'type': 'not_operator', 'children': ['108']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '110', 'type': 'binary_operator', 'children': ['111', '112'], 'value': '+'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '112', 'type': 'string', 'children': [], 'value': "'_org_name'"},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '121']},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '+'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '120', 'type': 'string', 'children': [], 'value': "'_org_name'"},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'SH_UNKNOWN_VALUE'},{'id': '122', 'type': 'if_statement', 'children': ['123', '129']},{'id': '123', 'type': 'not_operator', 'children': ['124']},{'id': '124', 'type': 'subscript', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '+'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '128', 'type': 'string', 'children': [], 'value': "'_name'"},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '137']},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '+'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '136', 'type': 'string', 'children': [], 'value': "'_name'"},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'SH_UNKNOWN_VALUE'},{'id': '138', 'type': 'if_statement', 'children': ['139', '145']},{'id': '139', 'type': 'not_operator', 'children': ['140']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '142', 'type': 'binary_operator', 'children': ['143', '144'], 'value': '+'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '144', 'type': 'string', 'children': [], 'value': "'_user_name'"},{'id': '145', 'type': 'block', 'children': ['146']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '153']},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '+'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '152', 'type': 'string', 'children': [], 'value': "'_user_name'"},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'SH_UNKNOWN_VALUE'},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'rol_author'},{'id': '157', 'type': 'string', 'children': [], 'value': "'author'"},{'id': '158', 'type': 'if_statement', 'children': ['159', '166']},{'id': '159', 'type': 'boolean_operator', 'children': ['160', '163'], 'value': 'and'},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': 'in'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'author_field'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'users_data'},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': '!='},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'author_field'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'rol_author'},{'id': '166', 'type': 'block', 'children': ['167', '177', '193', '205', '217']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'get_sh_identity'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'author_field'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'get_item_sh_fields'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189', '190']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'item_date'},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'rol_author'},{'id': '193', 'type': 'if_statement', 'children': ['194', '198']},{'id': '194', 'type': 'not_operator', 'children': ['195']},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '197', 'type': 'string', 'children': [], 'value': "'author_org_name'"},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '204']},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '203', 'type': 'string', 'children': [], 'value': "'author_org_name'"},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'SH_UNKNOWN_VALUE'},{'id': '205', 'type': 'if_statement', 'children': ['206', '210']},{'id': '206', 'type': 'not_operator', 'children': ['207']},{'id': '207', 'type': 'subscript', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '209', 'type': 'string', 'children': [], 'value': "'author_name'"},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '216']},{'id': '213', 'type': 'subscript', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '215', 'type': 'string', 'children': [], 'value': "'author_name'"},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'SH_UNKNOWN_VALUE'},{'id': '217', 'type': 'if_statement', 'children': ['218', '222']},{'id': '218', 'type': 'not_operator', 'children': ['219']},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '221', 'type': 'string', 'children': [], 'value': "'author_user_name'"},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '228']},{'id': '225', 'type': 'subscript', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'},{'id': '227', 'type': 'string', 'children': [], 'value': "'author_user_name'"},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'SH_UNKNOWN_VALUE'},{'id': '229', 'type': 'return_statement', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'} | def get_item_sh(self, item, roles=None, date_field=None):
eitem_sh = {}
author_field = self.get_field_author()
if not roles:
roles = [author_field]
if not date_field:
item_date = str_to_datetime(item[self.get_field_date()])
else:
item_date = str_to_datetime(item[date_field])
users_data = self.get_users_data(item)
for rol in roles:
if rol in users_data:
identity = self.get_sh_identity(item, rol)
eitem_sh.update(self.get_item_sh_fields(identity, item_date, rol=rol))
if not eitem_sh[rol + '_org_name']:
eitem_sh[rol + '_org_name'] = SH_UNKNOWN_VALUE
if not eitem_sh[rol + '_name']:
eitem_sh[rol + '_name'] = SH_UNKNOWN_VALUE
if not eitem_sh[rol + '_user_name']:
eitem_sh[rol + '_user_name'] = SH_UNKNOWN_VALUE
rol_author = 'author'
if author_field in users_data and author_field != rol_author:
identity = self.get_sh_identity(item, author_field)
eitem_sh.update(self.get_item_sh_fields(identity, item_date, rol=rol_author))
if not eitem_sh['author_org_name']:
eitem_sh['author_org_name'] = SH_UNKNOWN_VALUE
if not eitem_sh['author_name']:
eitem_sh['author_name'] = SH_UNKNOWN_VALUE
if not eitem_sh['author_user_name']:
eitem_sh['author_user_name'] = SH_UNKNOWN_VALUE
return eitem_sh |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sh_ids'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'backend_name'},{'id': '7', 'type': 'block', 'children': ['8', '19', '29']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'identity_tuple'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'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': 'identity'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sh_ids'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': '__get_sh_ids_cache'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'identity_tuple'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'backend_name'},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sh_ids'} | def get_sh_ids(self, identity, backend_name):
identity_tuple = tuple(identity.items())
sh_ids = self.__get_sh_ids_cache(identity_tuple, backend_name)
return sh_ids |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_sh_identity'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'identity_field'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '60', '64', '77', '81', '101', '109']},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '15']},{'id': '11', 'type': 'function_name', 'children': [], 'value': 'fill_list_identity'},{'id': '12', 'type': 'parameters', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'user_list_data'},{'id': '15', 'type': 'block', 'children': ['16', '26', '41', '58']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '21']},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '20', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '21', 'type': 'subscript', 'children': ['22', '25']},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'user_list_data'},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'string', 'children': [], 'value': "'__text__'"},{'id': '26', 'type': 'if_statement', 'children': ['27', '32']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'in'},{'id': '28', 'type': 'string', 'children': [], 'value': "'@'"},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '31', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '38']},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '37', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '40', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '41', 'type': 'if_statement', 'children': ['42', '47']},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'in'},{'id': '43', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'user_list_data'},{'id': '46', 'type': 'integer', 'children': [], 'value': '0'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '53']},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '52', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '53', 'type': 'subscript', 'children': ['54', '57']},{'id': '54', 'type': 'subscript', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'user_list_data'},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'id': '57', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '63', 'type': 'dictionary', 'children': []},{'id': '64', 'type': 'for_statement', 'children': ['65', '66', '70']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '66', 'type': 'list', 'children': ['67', '68', '69'], 'value': "['name', 'email', 'username']"},{'id': '67', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '68', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '69', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '76']},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '76', 'type': 'None', 'children': []},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '81', 'type': 'if_statement', 'children': ['82', '92']},{'id': '82', 'type': 'boolean_operator', 'children': ['83', '86'], 'value': 'and'},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'in'},{'id': '84', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '91'], 'value': '=='},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'dict'},{'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': 'user'},{'id': '96', 'type': 'subscript', 'children': ['97', '100']},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '99', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'identity_field'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'fill_list_identity'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'identity'} | def get_sh_identity(self, item, identity_field=None):
def fill_list_identity(identity, user_list_data):
identity['username'] = user_list_data[0]['__text__']
if '@' in identity['username']:
identity['email'] = identity['username']
if 'name' in user_list_data[0]:
identity['name'] = user_list_data[0]['name']
return identity
identity = {}
for field in ['name', 'email', 'username']:
identity[field] = None
user = item
if 'data' in item and type(item) == dict:
user = item['data'][identity_field]
identity = fill_list_identity(identity, user)
return identity |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'feed'},{'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': 'from_date'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'from_offset'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'latest_items'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'arthur_items'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'filter_classified'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '62', '72', '87', '100', '104', '147', '151', '203', '207', '218', '229', '319', '326']},{'id': '24', 'type': 'if_statement', 'children': ['25', '28', '47']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'fetch_archive'},{'id': '28', 'type': 'block', 'children': ['29', '39', '46']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'items'},{'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': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'perceval_backend'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'fetch_from_archive'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'feed_items'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '46', 'type': 'return_statement', 'children': []},{'id': '47', 'type': 'elif_clause', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'arthur_items'},{'id': '49', 'type': 'block', 'children': ['50', '54', '61']},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'arthur_items'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'feed_items'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '61', 'type': 'return_statement', 'children': []},{'id': '62', 'type': 'if_statement', 'children': ['63', '66']},{'id': '63', 'type': 'boolean_operator', 'children': ['64', '65'], 'value': 'and'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'from_offset'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'raise_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'string', 'children': [], 'value': '"Can\'t not feed using from_date and from_offset."'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'filters_'},{'id': '75', 'type': 'list', 'children': ['76'], 'value': '[get_repository_filter(self.perceval_backend,\n self.get_connector_name())]'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_repository_filter'},{'id': '78', 'type': 'argument_list', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'perceval_backend'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'get_connector_name'},{'id': '86', 'type': 'argument_list', 'children': []},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'perceval_backend'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'fetch'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'last_update'},{'id': '103', 'type': 'None', 'children': []},{'id': '104', 'type': 'if_statement', 'children': ['105', '110']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'in'},{'id': '106', 'type': 'string', 'children': [], 'value': "'from_date'"},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '110', 'type': 'block', 'children': ['111', '139']},{'id': '111', 'type': 'if_statement', 'children': ['112', '113', '118']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'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': 'last_update'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'from_date'},{'id': '118', 'type': 'else_clause', 'children': ['119']},{'id': '119', 'type': 'block', 'children': ['120', '133']},{'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': 'last_update'},{'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_last_update_from_es'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'filters_'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'filters_'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'last_update'},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'last_update'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '144', 'type': 'argument_list', 'children': ['145', '146']},{'id': '145', 'type': 'string', 'children': [], 'value': '"Incremental from: %s"'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'last_update'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '150', 'type': 'None', 'children': []},{'id': '151', 'type': 'if_statement', 'children': ['152', '157']},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'in'},{'id': '153', 'type': 'string', 'children': [], 'value': "'offset'"},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '157', 'type': 'block', 'children': ['158', '181']},{'id': '158', 'type': 'if_statement', 'children': ['159', '160', '165']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'from_offset'},{'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': 'offset'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'from_offset'},{'id': '165', 'type': 'else_clause', 'children': ['166']},{'id': '166', 'type': 'block', 'children': ['167']},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '170', 'type': 'call', 'children': ['171', '176']},{'id': '171', 'type': 'attribute', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'elastic'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'get_last_offset'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178']},{'id': '177', 'type': 'string', 'children': [], 'value': '"offset"'},{'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'filters_'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'filters_'},{'id': '181', 'type': 'if_statement', 'children': ['182', '185', '194']},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '184'], 'value': 'is'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '184', 'type': 'None', 'children': []},{'id': '185', 'type': 'block', 'children': ['186']},{'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': 'logger'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'string', 'children': [], 'value': '"Incremental from: %i offset"'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '194', 'type': 'else_clause', 'children': ['195']},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'string', 'children': [], 'value': '"Not incremental"'},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '206', 'type': 'dictionary', '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': 'category'},{'id': '210', 'type': 'None', 'children': []},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '217']},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '216', 'type': 'string', 'children': [], 'value': "'category'"},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'category'},{'id': '218', 'type': 'if_statement', 'children': ['219', '222']},{'id': '219', 'type': 'comparison_operator', 'children': ['220', '221'], 'value': 'is'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'filter_classified'},{'id': '221', 'type': 'None', 'children': []},{'id': '222', 'type': 'block', 'children': ['223']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '228']},{'id': '225', 'type': 'subscript', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '227', 'type': 'string', 'children': [], 'value': "'filter_classified'"},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'filter_classified'},{'id': '229', 'type': 'if_statement', 'children': ['230', '231', '250', '282', '305']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'latest_items'},{'id': '231', 'type': 'block', 'children': ['232', '238']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '237']},{'id': '234', 'type': 'subscript', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '236', 'type': 'string', 'children': [], 'value': "'latest_items'"},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'latest_items'},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '241', 'type': 'call', 'children': ['242', '247']},{'id': '242', 'type': 'attribute', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'perceval_backend'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'fetch'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'dictionary_splat', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '250', 'type': 'elif_clause', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'last_update'},{'id': '252', 'type': 'block', 'children': ['253', '264', '270']},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'last_update'},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'last_update'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'keyword_argument', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'tzinfo'},{'id': '263', 'type': 'None', 'children': []},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '269']},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '268', 'type': 'string', 'children': [], 'value': "'from_date'"},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'last_update'},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '273', 'type': 'call', 'children': ['274', '279']},{'id': '274', 'type': 'attribute', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'perceval_backend'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'fetch'},{'id': '279', 'type': 'argument_list', 'children': ['280']},{'id': '280', 'type': 'dictionary_splat', 'children': ['281']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '282', 'type': 'elif_clause', 'children': ['283', '286']},{'id': '283', 'type': 'comparison_operator', 'children': ['284', '285'], 'value': 'is'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '285', 'type': 'None', 'children': []},{'id': '286', 'type': 'block', 'children': ['287', '293']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '292']},{'id': '289', 'type': 'subscript', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '291', 'type': 'string', 'children': [], 'value': "'offset'"},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '293', 'type': 'expression_statement', 'children': ['294']},{'id': '294', 'type': 'assignment', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'items'},{'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': 'perceval_backend'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'fetch'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'dictionary_splat', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '305', 'type': 'else_clause', 'children': ['306']},{'id': '306', 'type': 'block', 'children': ['307']},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'assignment', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'items'},{'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': 'self'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'perceval_backend'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'fetch'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'dictionary_splat', 'children': ['318']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'call', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'feed_items'},{'id': '324', 'type': 'argument_list', 'children': ['325']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '326', 'type': 'expression_statement', 'children': ['327']},{'id': '327', 'type': 'call', 'children': ['328', '331']},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'update_items'},{'id': '331', 'type': 'argument_list', 'children': []} | def feed(self, from_date=None, from_offset=None, category=None,
latest_items=None, arthur_items=None, filter_classified=None):
if self.fetch_archive:
items = self.perceval_backend.fetch_from_archive()
self.feed_items(items)
return
elif arthur_items:
items = arthur_items
self.feed_items(items)
return
if from_date and from_offset:
raise RuntimeError("Can't not feed using from_date and from_offset.")
filters_ = [get_repository_filter(self.perceval_backend,
self.get_connector_name())]
signature = inspect.signature(self.perceval_backend.fetch)
last_update = None
if 'from_date' in signature.parameters:
if from_date:
last_update = from_date
else:
self.last_update = self.get_last_update_from_es(filters_=filters_)
last_update = self.last_update
logger.info("Incremental from: %s", last_update)
offset = None
if 'offset' in signature.parameters:
if from_offset:
offset = from_offset
else:
offset = self.elastic.get_last_offset("offset", filters_=filters_)
if offset is not None:
logger.info("Incremental from: %i offset", offset)
else:
logger.info("Not incremental")
params = {}
if category is not None:
params['category'] = category
if filter_classified is not None:
params['filter_classified'] = filter_classified
if latest_items:
params['latest_items'] = latest_items
items = self.perceval_backend.fetch(**params)
elif last_update:
last_update = last_update.replace(tzinfo=None)
params['from_date'] = last_update
items = self.perceval_backend.fetch(**params)
elif offset is not None:
params['offset'] = offset
items = self.perceval_backend.fetch(**params)
else:
items = self.perceval_backend.fetch(**params)
self.feed_items(items)
self.update_items() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_identities'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '6', 'type': 'block', 'children': ['7', '156', '164', '270', '376']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '13']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'add_sh_github_identity'},{'id': '9', 'type': 'parameters', 'children': ['10', '11', '12']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'user_field'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '13', 'type': 'block', 'children': ['14', '18', '48', '53', '61', '74']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'github_repo'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'if_statement', 'children': ['19', '24']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'in'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'GITHUB'},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '23', 'type': 'string', 'children': [], 'value': "'origin'"},{'id': '24', 'type': 'block', 'children': ['25', '37']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'github_repo'},{'id': '28', 'type': 'call', 'children': ['29', '34']},{'id': '29', 'type': 'attribute', 'children': ['30', '33']},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '32', 'type': 'string', 'children': [], 'value': "'origin'"},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'GITHUB'},{'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': 'github_repo'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46', '47']},{'id': '45', 'type': 'string', 'children': [], 'value': "'.git$'"},{'id': '46', 'type': 'string', 'children': [], 'value': "''"},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'github_repo'},{'id': '48', 'type': 'if_statement', 'children': ['49', '51']},{'id': '49', 'type': 'not_operator', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'github_repo'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'return_statement', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'user_data'},{'id': '56', 'type': 'subscript', 'children': ['57', '60']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '59', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'user_field'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sh_identity'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'SortingHat'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'get_github_commit_username'},{'id': '68', 'type': 'argument_list', 'children': ['69', '72', '73']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'sh_db'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'SH_GIT_COMMIT'},{'id': '74', 'type': 'if_statement', 'children': ['75', '77', '126']},{'id': '75', 'type': 'not_operator', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'sh_identity'},{'id': '77', 'type': 'block', 'children': ['78', '90', '100', '109', '115']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'gh_username'},{'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': 'get_github_login'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87', '88', '89']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'user_data'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'rol'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'commit_hash'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'github_repo'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97', '98', '99']},{'id': '96', 'type': 'string', 'children': [], 'value': '"Adding new identity %s to SH %s: %s"'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'gh_username'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'SH_GIT_COMMIT'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'get_sh_identity'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'user_data'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '114']},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '113', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'gh_username'},{'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': 'SortingHat'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'add_identity'},{'id': '120', 'type': 'argument_list', 'children': ['121', '124', '125']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sh_db'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'SH_GIT_COMMIT'},{'id': '126', 'type': 'else_clause', 'children': ['127']},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'if_statement', 'children': ['129', '134']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'not'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'user_data'},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'github_logins'},{'id': '134', 'type': 'block', 'children': ['135', '145']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '142']},{'id': '137', 'type': 'subscript', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'github_logins'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'user_data'},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'sh_identity'},{'id': '144', 'type': 'string', 'children': [], 'value': "'username'"},{'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': 'logger'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '150', 'type': 'argument_list', 'children': ['151', '152', '155']},{'id': '151', 'type': 'string', 'children': [], 'value': '"GitHub-commit exists. username:%s user:%s"'},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'sh_identity'},{'id': '154', 'type': 'string', 'children': [], 'value': "'username'"},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'user_data'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'commit_hash'},{'id': '159', 'type': 'subscript', 'children': ['160', '163']},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '162', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '163', 'type': 'string', 'children': [], 'value': "'commit'"},{'id': '164', 'type': 'if_statement', 'children': ['165', '170']},{'id': '165', 'type': 'subscript', 'children': ['166', '169']},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '168', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '169', 'type': 'string', 'children': [], 'value': "'Author'"},{'id': '170', 'type': 'block', 'children': ['171', '186', '201']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '174', 'type': 'call', 'children': ['175', '180']},{'id': '175', 'type': 'attribute', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'AUTHOR_P2P_REGEX'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'subscript', 'children': ['182', '185']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '184', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '185', 'type': 'string', 'children': [], 'value': '"Author"'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '189', 'type': 'call', 'children': ['190', '195']},{'id': '190', 'type': 'attribute', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'AUTHOR_P2P_NEW_REGEX'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'subscript', 'children': ['197', '200']},{'id': '197', 'type': 'subscript', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '199', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '200', 'type': 'string', 'children': [], 'value': '"Author"'},{'id': '201', 'type': 'if_statement', 'children': ['202', '210', '240']},{'id': '202', 'type': 'boolean_operator', 'children': ['203', '207'], 'value': 'and'},{'id': '203', 'type': '()', 'children': ['204']},{'id': '204', 'type': 'boolean_operator', 'children': ['205', '206'], 'value': 'or'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'pair_programming'},{'id': '210', 'type': 'block', 'children': ['211', '224']},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'authors'},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '217', 'type': 'identifier', 'children': [], 'value': '__get_authors'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'subscript', 'children': ['220', '223']},{'id': '220', 'type': 'subscript', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '222', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '223', 'type': 'string', 'children': [], 'value': '"Author"'},{'id': '224', 'type': 'for_statement', 'children': ['225', '226', '227']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'authors'},{'id': '227', 'type': 'block', 'children': ['228', '237']},{'id': '228', 'type': 'expression_statement', 'children': ['229']},{'id': '229', 'type': 'assignment', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'get_sh_identity'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'yield', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '240', 'type': 'else_clause', 'children': ['241']},{'id': '241', 'type': 'block', 'children': ['242', '255', '258']},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'user'},{'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': 'get_sh_identity'},{'id': '249', 'type': 'argument_list', 'children': ['250']},{'id': '250', 'type': 'subscript', 'children': ['251', '254']},{'id': '251', 'type': 'subscript', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '253', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '254', 'type': 'string', 'children': [], 'value': '"Author"'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'yield', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '258', 'type': 'if_statement', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'github_token'},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'add_sh_github_identity'},{'id': '266', 'type': 'argument_list', 'children': ['267', '268', '269']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '268', 'type': 'string', 'children': [], 'value': "'Author'"},{'id': '269', 'type': 'string', 'children': [], 'value': "'author'"},{'id': '270', 'type': 'if_statement', 'children': ['271', '276']},{'id': '271', 'type': 'subscript', 'children': ['272', '275']},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '274', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '275', 'type': 'string', 'children': [], 'value': "'Commit'"},{'id': '276', 'type': 'block', 'children': ['277', '292', '307']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '280', 'type': 'call', 'children': ['281', '286']},{'id': '281', 'type': 'attribute', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'AUTHOR_P2P_REGEX'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'subscript', 'children': ['288', '291']},{'id': '288', 'type': 'subscript', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '290', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '291', 'type': 'string', 'children': [], 'value': '"Commit"'},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'assignment', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '295', 'type': 'call', 'children': ['296', '301']},{'id': '296', 'type': 'attribute', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'AUTHOR_P2P_NEW_REGEX'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'subscript', 'children': ['303', '306']},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '305', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '306', 'type': 'string', 'children': [], 'value': '"Author"'},{'id': '307', 'type': 'if_statement', 'children': ['308', '316', '346']},{'id': '308', 'type': 'boolean_operator', 'children': ['309', '313'], 'value': 'and'},{'id': '309', 'type': '()', 'children': ['310']},{'id': '310', 'type': 'boolean_operator', 'children': ['311', '312'], 'value': 'or'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'pair_programming'},{'id': '316', 'type': 'block', 'children': ['317', '330']},{'id': '317', 'type': 'expression_statement', 'children': ['318']},{'id': '318', 'type': 'assignment', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'committers'},{'id': '320', 'type': 'call', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '323', 'type': 'identifier', 'children': [], 'value': '__get_authors'},{'id': '324', 'type': 'argument_list', 'children': ['325']},{'id': '325', 'type': 'subscript', 'children': ['326', '329']},{'id': '326', 'type': 'subscript', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '328', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '329', 'type': 'string', 'children': [], 'value': "'Commit'"},{'id': '330', 'type': 'for_statement', 'children': ['331', '332', '333']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'committer'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'committers'},{'id': '333', 'type': 'block', 'children': ['334', '343']},{'id': '334', 'type': 'expression_statement', 'children': ['335']},{'id': '335', 'type': 'assignment', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '337', 'type': 'call', 'children': ['338', '341']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'get_sh_identity'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'committer'},{'id': '343', 'type': 'expression_statement', 'children': ['344']},{'id': '344', 'type': 'yield', 'children': ['345']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '346', 'type': 'else_clause', 'children': ['347']},{'id': '347', 'type': 'block', 'children': ['348', '361', '364']},{'id': '348', 'type': 'expression_statement', 'children': ['349']},{'id': '349', 'type': 'assignment', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '351', 'type': 'call', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'get_sh_identity'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'subscript', 'children': ['357', '360']},{'id': '357', 'type': 'subscript', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '359', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '360', 'type': 'string', 'children': [], 'value': "'Commit'"},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'yield', 'children': ['363']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '364', 'type': 'if_statement', 'children': ['365', '368']},{'id': '365', 'type': 'attribute', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'github_token'},{'id': '368', 'type': 'block', 'children': ['369']},{'id': '369', 'type': 'expression_statement', 'children': ['370']},{'id': '370', 'type': 'call', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'add_sh_github_identity'},{'id': '372', 'type': 'argument_list', 'children': ['373', '374', '375']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '374', 'type': 'string', 'children': [], 'value': "'Commit'"},{'id': '375', 'type': 'string', 'children': [], 'value': "'committer'"},{'id': '376', 'type': 'if_statement', 'children': ['377', '386']},{'id': '377', 'type': 'boolean_operator', 'children': ['378', '383'], 'value': 'and'},{'id': '378', 'type': 'comparison_operator', 'children': ['379', '380'], 'value': 'in'},{'id': '379', 'type': 'string', 'children': [], 'value': "'Signed-off-by'"},{'id': '380', 'type': 'subscript', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '382', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '383', 'type': 'attribute', 'children': ['384', '385']},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'pair_programming'},{'id': '386', 'type': 'block', 'children': ['387', '395']},{'id': '387', 'type': 'expression_statement', 'children': ['388']},{'id': '388', 'type': 'assignment', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'signers'},{'id': '390', 'type': 'subscript', 'children': ['391', '394']},{'id': '391', 'type': 'subscript', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '393', 'type': 'string', 'children': [], 'value': "'data'"},{'id': '394', 'type': 'string', 'children': [], 'value': '"Signed-off-by"'},{'id': '395', 'type': 'for_statement', 'children': ['396', '397', '398']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'signer'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'signers'},{'id': '398', 'type': 'block', 'children': ['399', '408']},{'id': '399', 'type': 'expression_statement', 'children': ['400']},{'id': '400', 'type': 'assignment', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '402', 'type': 'call', 'children': ['403', '406']},{'id': '403', 'type': 'attribute', 'children': ['404', '405']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'get_sh_identity'},{'id': '406', 'type': 'argument_list', 'children': ['407']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'signer'},{'id': '408', 'type': 'expression_statement', 'children': ['409']},{'id': '409', 'type': 'yield', 'children': ['410']},{'id': '410', 'type': 'identifier', 'children': [], 'value': 'user'} | def get_identities(self, item):
def add_sh_github_identity(user, user_field, rol):
github_repo = None
if GITHUB in item['origin']:
github_repo = item['origin'].replace(GITHUB, '')
github_repo = re.sub('.git$', '', github_repo)
if not github_repo:
return
user_data = item['data'][user_field]
sh_identity = SortingHat.get_github_commit_username(self.sh_db, user, SH_GIT_COMMIT)
if not sh_identity:
gh_username = self.get_github_login(user_data, rol, commit_hash, github_repo)
logger.debug("Adding new identity %s to SH %s: %s", gh_username, SH_GIT_COMMIT, user)
user = self.get_sh_identity(user_data)
user['username'] = gh_username
SortingHat.add_identity(self.sh_db, user, SH_GIT_COMMIT)
else:
if user_data not in self.github_logins:
self.github_logins[user_data] = sh_identity['username']
logger.debug("GitHub-commit exists. username:%s user:%s",
sh_identity['username'], user_data)
commit_hash = item['data']['commit']
if item['data']['Author']:
m = self.AUTHOR_P2P_REGEX.match(item['data']["Author"])
n = self.AUTHOR_P2P_NEW_REGEX.match(item['data']["Author"])
if (m or n) and self.pair_programming:
authors = self.__get_authors(item['data']["Author"])
for author in authors:
user = self.get_sh_identity(author)
yield user
else:
user = self.get_sh_identity(item['data']["Author"])
yield user
if self.github_token:
add_sh_github_identity(user, 'Author', 'author')
if item['data']['Commit']:
m = self.AUTHOR_P2P_REGEX.match(item['data']["Commit"])
n = self.AUTHOR_P2P_NEW_REGEX.match(item['data']["Author"])
if (m or n) and self.pair_programming:
committers = self.__get_authors(item['data']['Commit'])
for committer in committers:
user = self.get_sh_identity(committer)
yield user
else:
user = self.get_sh_identity(item['data']['Commit'])
yield user
if self.github_token:
add_sh_github_identity(user, 'Commit', 'committer')
if 'Signed-off-by' in item['data'] and self.pair_programming:
signers = item['data']["Signed-off-by"]
for signer in signers:
user = self.get_sh_identity(signer)
yield user |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'areas_of_code'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'git_enrich'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'in_conn'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'out_conn'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'block_size'},{'id': '9', 'type': 'integer', 'children': [], 'value': '100'},{'id': '10', 'type': 'block', 'children': ['11', '29', '37']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'aoc'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'AreasOfCode'},{'id': '16', 'type': 'argument_list', 'children': ['17', '20', '23', '26']},{'id': '17', 'type': 'keyword_argument', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'in_connector'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'in_conn'},{'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'out_connector'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'out_conn'},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'block_size'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'block_size'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'git_enrich'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'git_enrich'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ndocs'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'aoc'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'analyze'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'return_statement', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'ndocs'} | def areas_of_code(git_enrich, in_conn, out_conn, block_size=100):
aoc = AreasOfCode(in_connector=in_conn, out_connector=out_conn, block_size=block_size,
git_enrich=git_enrich)
ndocs = aoc.analyze()
return ndocs |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_make_serializer'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'meas'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'rm_none'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'extra_tags'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'placeholder'},{'id': '9', 'type': 'block', 'children': ['10', '16', '20', '24', '28', '32', '177', '183', '200', '211', '218', '225', '229', '263', '269', '292']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_validate_schema'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'placeholder'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '23', 'type': 'list', 'children': [], 'value': '[]'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'meas'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'meas'},{'id': '32', 'type': 'for_statement', 'children': ['33', '36', '41']},{'id': '33', 'type': 'pattern_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'if_statement', 'children': ['43', '46', '51', '60', '78', '96', '108', '120', '134', '146', '158', '170']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'MEASUREMENT'},{'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': 'meas'},{'id': '50', 'type': 'string', 'children': [], 'value': 'f"{{i.{k}}}"'},{'id': '51', 'type': 'elif_clause', 'children': ['52', '55']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'TIMEINT'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '59', 'type': 'string', 'children': [], 'value': 'f"{{i.{k}}}"'},{'id': '60', 'type': 'elif_clause', 'children': ['61', '64']},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'TIMESTR'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'if_statement', 'children': ['66', '67', '72']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'pd'},{'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': 'ts'},{'id': '71', 'type': 'string', 'children': [], 'value': 'f"{{pd.Timestamp(i.{k} or 0).value}}"'},{'id': '72', 'type': 'else_clause', 'children': ['73']},{'id': '73', 'type': 'block', 'children': ['74']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '77', 'type': 'string', 'children': [], 'value': 'f"{{dt_to_int(str_to_dt(i.{k}))}}"'},{'id': '78', 'type': 'elif_clause', 'children': ['79', '82']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'is'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'TIMEDT'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'if_statement', 'children': ['84', '85', '90']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '89', 'type': 'string', 'children': [], 'value': 'f"{{pd.Timestamp(i.{k} or 0).value}}"'},{'id': '90', 'type': 'else_clause', 'children': ['91']},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '95', 'type': 'string', 'children': [], 'value': 'f"{{dt_to_int(i.{k})}}"'},{'id': '96', 'type': 'elif_clause', 'children': ['97', '100']},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': 'is'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'TAG'},{'id': '100', 'type': 'block', 'children': ['101']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': 'f"{k}={{str(i.{k}).translate(tag_escape)}}"'},{'id': '108', 'type': 'elif_clause', 'children': ['109', '112']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '111'], 'value': 'is'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'TAGENUM'},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'string', 'children': [], 'value': 'f"{k}={{getattr(i.{k}, \'name\', i.{k} or None)}}"'},{'id': '120', 'type': 'elif_clause', 'children': ['121', '126']},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'in'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '123', 'type': 'tuple', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'FLOAT'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'BOOL'},{'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': 'fields'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'string', 'children': [], 'value': 'f"{k}={{i.{k}}}"'},{'id': '134', 'type': 'elif_clause', 'children': ['135', '138']},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': 'is'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'INT'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'string', 'children': [], 'value': 'f"{k}={{i.{k}}}i"'},{'id': '146', 'type': 'elif_clause', 'children': ['147', '150']},{'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'is'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'STR'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'string', 'children': [], 'value': 'f"{k}=\\\\\\"{{str(i.{k}).translate(str_escape)}}\\\\\\""'},{'id': '158', 'type': 'elif_clause', 'children': ['159', '162']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': 'is'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'ENUM'},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'string', 'children': [], 'value': 'f"{k}=\\\\\\"{{getattr(i.{k}, \'name\', i.{k} or None)}}\\\\\\""'},{'id': '170', 'type': 'else_clause', 'children': ['171']},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'raise_statement', 'children': ['173']},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'SchemaError'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'string', 'children': [], 'value': 'f"Invalid attribute type {k!r}: {t!r}"'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'extra_tags'},{'id': '180', 'type': 'boolean_operator', 'children': ['181', '182'], 'value': 'or'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'extra_tags'},{'id': '182', 'type': 'dictionary', 'children': []},{'id': '183', 'type': 'for_statement', 'children': ['184', '187', '192']},{'id': '184', 'type': 'pattern_list', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '187', 'type': 'call', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'extra_tags'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '191', 'type': 'argument_list', 'children': []},{'id': '192', 'type': 'block', 'children': ['193']},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'string', 'children': [], 'value': 'f"{k}={v}"'},{'id': '200', 'type': 'if_statement', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'placeholder'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210']},{'id': '209', 'type': 'integer', 'children': [], 'value': '0'},{'id': '210', 'type': 'string', 'children': [], 'value': 'f"_=true"'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '214', 'type': 'conditional_expression', 'children': ['215', '216', '217'], 'value': 'if'},{'id': '215', 'type': 'string', 'children': [], 'value': "','"},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '217', 'type': 'string', 'children': [], 'value': "''"},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '221', 'type': 'conditional_expression', 'children': ['222', '223', '224'], 'value': 'if'},{'id': '222', 'type': 'string', 'children': [], 'value': "f' {ts}'"},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '224', 'type': 'string', 'children': [], 'value': "''"},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '228', 'type': 'string', 'children': [], 'value': 'f"{meas}{sep}{\',\'.join(tags)} {\',\'.join(fields)}{ts}"'},{'id': '229', 'type': 'if_statement', 'children': ['230', '231', '249']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'rm_none'},{'id': '231', 'type': 'block', 'children': ['232', '236']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'pat'},{'id': '235', 'type': 'string', 'children': [], 'value': 'r\',\\w+="?None"?i?\''},{'id': '236', 'type': 'expression_statement', 'children': ['237']},{'id': '237', 'type': 'assignment', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '239', 'type': 'call', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'eval'},{'id': '241', 'type': 'argument_list', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'string', 'children': [], 'value': '\'lambda i: re.sub(r\\\'{}\\\', "", f"{}").encode()\''},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '246', 'type': 'argument_list', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'pat'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '249', 'type': 'else_clause', 'children': ['250']},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'eval'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'string', 'children': [], 'value': '\'lambda i: f"{}".encode()\''},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'assignment', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '267', 'type': 'identifier', 'children': [], 'value': '__doc__'},{'id': '268', 'type': 'string', 'children': [], 'value': '"Returns InfluxDB line protocol representation of user-defined class"'},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '273', 'type': 'identifier', 'children': [], 'value': '_args'},{'id': '274', 'type': 'call', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '276', 'type': 'argument_list', 'children': ['277', '280', '283', '286', '289']},{'id': '277', 'type': 'keyword_argument', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'meas'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'meas'},{'id': '280', 'type': 'keyword_argument', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'schema'},{'id': '283', 'type': 'keyword_argument', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'rm_none'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'rm_none'},{'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'extra_tags'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'extra_tags'},{'id': '289', 'type': 'keyword_argument', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'placeholder'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'placeholder'},{'id': '292', 'type': 'return_statement', 'children': ['293']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'f'} | def _make_serializer(meas, schema, rm_none, extra_tags, placeholder):
_validate_schema(schema, placeholder)
tags = []
fields = []
ts = None
meas = meas
for k, t in schema.items():
if t is MEASUREMENT:
meas = f"{{i.{k}}}"
elif t is TIMEINT:
ts = f"{{i.{k}}}"
elif t is TIMESTR:
if pd:
ts = f"{{pd.Timestamp(i.{k} or 0).value}}"
else:
ts = f"{{dt_to_int(str_to_dt(i.{k}))}}"
elif t is TIMEDT:
if pd:
ts = f"{{pd.Timestamp(i.{k} or 0).value}}"
else:
ts = f"{{dt_to_int(i.{k})}}"
elif t is TAG:
tags.append(f"{k}={{str(i.{k}).translate(tag_escape)}}")
elif t is TAGENUM:
tags.append(f"{k}={{getattr(i.{k}, 'name', i.{k} or None)}}")
elif t in (FLOAT, BOOL):
fields.append(f"{k}={{i.{k}}}")
elif t is INT:
fields.append(f"{k}={{i.{k}}}i")
elif t is STR:
fields.append(f"{k}=\\\"{{str(i.{k}).translate(str_escape)}}\\\"")
elif t is ENUM:
fields.append(f"{k}=\\\"{{getattr(i.{k}, 'name', i.{k} or None)}}\\\"")
else:
raise SchemaError(f"Invalid attribute type {k!r}: {t!r}")
extra_tags = extra_tags or {}
for k, v in extra_tags.items():
tags.append(f"{k}={v}")
if placeholder:
fields.insert(0, f"_=true")
sep = ',' if tags else ''
ts = f' {ts}' if ts else ''
fmt = f"{meas}{sep}{','.join(tags)} {','.join(fields)}{ts}"
if rm_none:
pat = r',\w+="?None"?i?'
f = eval('lambda i: re.sub(r\'{}\', "", f"{}").encode()'.format(pat, fmt))
else:
f = eval('lambda i: f"{}".encode()'.format(fmt))
f.__doc__ = "Returns InfluxDB line protocol representation of user-defined class"
f._args = dict(meas=meas, schema=schema, rm_none=rm_none,
extra_tags=extra_tags, placeholder=placeholder)
return f |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iterpoints'},{'id': '3', 'type': 'parameters', 'children': ['4', '8']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '8', 'type': 'typed_default_parameter', 'children': ['9', '10', '16']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'parser'},{'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': 'Callable'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'type', 'children': ['18']},{'id': '18', 'type': 'generic_type', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'Iterator'},{'id': '20', 'type': 'type_parameter', 'children': ['21']},{'id': '21', 'type': 'type', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'Any'},{'id': '23', 'type': 'block', 'children': ['24', '120']},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '29']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'statement'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '28', 'type': 'string', 'children': [], 'value': "'results'"},{'id': '29', 'type': 'block', 'children': ['30', '36']},{'id': '30', 'type': 'if_statement', 'children': ['31', '34']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'not'},{'id': '32', 'type': 'string', 'children': [], 'value': "'series'"},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'statement'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'continue_statement', 'children': []},{'id': '36', 'type': 'for_statement', 'children': ['37', '38', '41']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'statement'},{'id': '40', 'type': 'string', 'children': [], 'value': "'series'"},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'if_statement', 'children': ['43', '46', '55', '106']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'generator_expression', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '54', 'type': 'string', 'children': [], 'value': "'values'"},{'id': '55', 'type': 'elif_clause', 'children': ['56', '66']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'},{'id': '57', 'type': 'string', 'children': [], 'value': "'meta'"},{'id': '58', 'type': 'attribute', 'children': ['59', '65']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '66', 'type': 'block', 'children': ['67', '83', '91']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '70', 'type': 'dictionary_comprehension', 'children': ['71', '76', '79']},{'id': '71', 'type': 'pair', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '73', 'type': 'subscript', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '76', 'type': 'for_in_clause', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '79', 'type': 'if_clause', 'children': ['80']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': '!='},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '82', 'type': 'string', 'children': [], 'value': "'values'"},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '88']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '87', 'type': 'string', 'children': [], 'value': "'statement_id'"},{'id': '88', 'type': 'subscript', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'statement'},{'id': '90', 'type': 'string', 'children': [], 'value': "'statement_id'"},{'id': '91', 'type': 'return_statement', 'children': ['92']},{'id': '92', 'type': 'generator_expression', 'children': ['93', '101']},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '95', 'type': 'argument_list', 'children': ['96', '98']},{'id': '96', 'type': 'list_splat', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'meta'},{'id': '101', 'type': 'for_in_clause', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '103', 'type': 'subscript', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '105', 'type': 'string', 'children': [], 'value': "'values'"},{'id': '106', 'type': 'else_clause', 'children': ['107']},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'return_statement', 'children': ['109']},{'id': '109', 'type': 'generator_expression', 'children': ['110', '115']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'parser'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'list_splat', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '115', 'type': 'for_in_clause', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'series'},{'id': '119', 'type': 'string', 'children': [], 'value': "'values'"},{'id': '120', 'type': 'return_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'list', 'children': [], 'value': '[]'} | def iterpoints(resp: dict, parser: Optional[Callable] = None) -> Iterator[Any]:
for statement in resp['results']:
if 'series' not in statement:
continue
for series in statement['series']:
if parser is None:
return (x for x in series['values'])
elif 'meta' in inspect.signature(parser).parameters:
meta = {k: series[k] for k in series if k != 'values'}
meta['statement_id'] = statement['statement_id']
return (parser(*x, meta=meta) for x in series['values'])
else:
return (parser(*x) for x in series['values'])
return iter([]) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'serialize'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'measurement'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'tag_columns'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'extra_tags'},{'id': '11', 'type': 'type', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '13', 'type': 'block', 'children': ['14', '24', '41', '50', '65', '69', '73', '90', '177', '197', '214']},{'id': '14', 'type': 'if_statement', 'children': ['15', '18']},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'measurement'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'raise_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': '"Missing \'measurement\'"'},{'id': '24', 'type': 'if_statement', 'children': ['25', '35']},{'id': '25', 'type': 'not_operator', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '28', 'type': 'argument_list', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'DatetimeIndex'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'raise_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'string', 'children': [], 'value': "'DataFrame index is not DatetimeIndex'"},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'tag_columns'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '49'], 'value': 'or'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'tag_columns'},{'id': '49', 'type': 'list', 'children': [], 'value': '[]'},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'isnull'},{'id': '53', 'type': 'call', 'children': ['54', '61']},{'id': '54', 'type': 'attribute', 'children': ['55', '60']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'isnull'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'keyword_argument', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '64', 'type': 'integer', 'children': [], 'value': '1'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '68', 'type': 'list', 'children': [], 'value': '[]'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '72', 'type': 'list', 'children': [], 'value': '[]'},{'id': '73', 'type': 'for_statement', 'children': ['74', '77', '82']},{'id': '74', 'type': 'pattern_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'extra_tags'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '81', 'type': 'argument_list', 'children': []},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'string', 'children': [], 'value': 'f"{k}={escape(v, key_escape)}"'},{'id': '90', 'type': 'for_statement', 'children': ['91', '96', '106']},{'id': '91', 'type': 'pattern_list', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '93', 'type': 'tuple_pattern', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '105']},{'id': '100', 'type': 'attribute', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'dtypes'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'block', 'children': ['107', '116']},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'translate'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'key_escape'},{'id': '116', 'type': 'if_statement', 'children': ['117', '120', '128', '146', '168']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': 'in'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'tag_columns'},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'string', 'children': [], 'value': 'f"{k}={{p[{i+1}]}}"'},{'id': '128', 'type': 'elif_clause', 'children': ['129', '138']},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '131', 'type': 'argument_list', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'integer'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'string', 'children': [], 'value': 'f"{k}={{p[{i+1}]}}i"'},{'id': '146', 'type': 'elif_clause', 'children': ['147', '160']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '149', 'type': 'argument_list', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '153', 'type': 'tuple', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'bool_'},{'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': 'fields'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'string', 'children': [], 'value': 'f"{k}={{p[{i+1}]}}"'},{'id': '168', 'type': 'else_clause', 'children': ['169']},{'id': '169', 'type': 'block', 'children': ['170']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'string', 'children': [], 'value': 'f"{k}=\\"{{p[{i+1}]}}\\""'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '180', 'type': 'tuple', 'children': ['181', '182', '183', '189', '190', '196']},{'id': '181', 'type': 'string', 'children': [], 'value': "f'{measurement}'"},{'id': '182', 'type': 'string', 'children': [], 'value': 'f\'{"," if tags else ""}\''},{'id': '183', 'type': 'call', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'string', 'children': [], 'value': "','"},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'tags'},{'id': '189', 'type': 'string', 'children': [], 'value': "' '"},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'string', 'children': [], 'value': "','"},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '196', 'type': 'string', 'children': [], 'value': "' {p[0].value}'"},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '200', 'type': 'call', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'eval'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'string', 'children': [], 'value': '"lambda p: f\'{}\'"'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'string', 'children': [], 'value': "''"},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '212', 'type': 'argument_list', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '214', 'type': 'if_statement', 'children': ['215', '220', '290']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'isnull'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '219', 'type': 'argument_list', 'children': []},{'id': '220', 'type': 'block', 'children': ['221', '235', '242', '274']},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'lp'},{'id': '224', 'type': 'call', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '226', 'type': 'argument_list', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': '_itertuples'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'subscript', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '233', 'type': 'unary_operator', 'children': ['234'], 'value': '~'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'isnull'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'rep'},{'id': '238', 'type': 'call', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': '_replace'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'lp_nan'},{'id': '245', 'type': 'generator_expression', 'children': ['246', '266']},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'reduce'},{'id': '248', 'type': 'argument_list', 'children': ['249', '261', '262']},{'id': '249', 'type': 'lambda', 'children': ['250', '253']},{'id': '250', 'type': 'lambda_parameters', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '253', 'type': 'call', 'children': ['254', '257']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '257', 'type': 'argument_list', 'children': ['258', '260']},{'id': '258', 'type': 'list_splat', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'rep'},{'id': '262', 'type': 'call', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '266', 'type': 'for_in_clause', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '268', 'type': 'call', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': '_itertuples'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'subscript', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'isnull'},{'id': '274', 'type': 'return_statement', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '288']},{'id': '276', 'type': 'attribute', 'children': ['277', '287']},{'id': '277', 'type': 'call', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '284', 'type': 'argument_list', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'lp'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'lp_nan'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '290', 'type': 'else_clause', 'children': ['291']},{'id': '291', 'type': 'block', 'children': ['292']},{'id': '292', 'type': 'return_statement', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '309']},{'id': '294', 'type': 'attribute', 'children': ['295', '308']},{'id': '295', 'type': 'call', 'children': ['296', '299']},{'id': '296', 'type': 'attribute', 'children': ['297', '298']},{'id': '297', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '302', 'type': 'argument_list', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': '_itertuples'},{'id': '306', 'type': 'argument_list', 'children': ['307']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'df'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'string', 'children': [], 'value': "'utf-8'"} | def serialize(df, measurement, tag_columns=None, **extra_tags) -> bytes:
if measurement is None:
raise ValueError("Missing 'measurement'")
if not isinstance(df.index, pd.DatetimeIndex):
raise ValueError('DataFrame index is not DatetimeIndex')
tag_columns = set(tag_columns or [])
isnull = df.isnull().any(axis=1)
tags = []
fields = []
for k, v in extra_tags.items():
tags.append(f"{k}={escape(v, key_escape)}")
for i, (k, v) in enumerate(df.dtypes.items()):
k = k.translate(key_escape)
if k in tag_columns:
tags.append(f"{k}={{p[{i+1}]}}")
elif issubclass(v.type, np.integer):
fields.append(f"{k}={{p[{i+1}]}}i")
elif issubclass(v.type, (np.float, np.bool_)):
fields.append(f"{k}={{p[{i+1}]}}")
else:
fields.append(f"{k}=\"{{p[{i+1}]}}\"")
fmt = (f'{measurement}', f'{"," if tags else ""}', ','.join(tags),
' ', ','.join(fields), ' {p[0].value}')
f = eval("lambda p: f'{}'".format(''.join(fmt)))
if isnull.any():
lp = map(f, _itertuples(df[~isnull]))
rep = _replace(df)
lp_nan = (reduce(lambda a, b: re.sub(*b, a), rep, f(p))
for p in _itertuples(df[isnull]))
return '\n'.join(chain(lp, lp_nan)).encode('utf-8')
else:
return '\n'.join(map(f, _itertuples(df))).encode('utf-8') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_my_feed'},{'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': 'limit'},{'id': '7', 'type': 'integer', 'children': [], 'value': '150'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '10', 'type': 'integer', 'children': [], 'value': '20'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '13', 'type': 'string', 'children': [], 'value': '"updated"'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'nid'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '46']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'r'},{'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': 'request'},{'id': '25', 'type': 'argument_list', 'children': ['26', '29', '32']},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '28', 'type': 'string', 'children': [], 'value': '"network.get_my_feed"'},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'nid'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'nid'},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '36', 'type': 'argument_list', 'children': ['37', '40', '43']},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_handle_error'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '53', 'type': 'string', 'children': [], 'value': '"Could not retrieve your feed."'} | def get_my_feed(self, limit=150, offset=20, sort="updated", nid=None):
r = self.request(
method="network.get_my_feed",
nid=nid,
data=dict(
limit=limit,
offset=offset,
sort=sort
)
)
return self._handle_error(r, "Could not retrieve your feed.") |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_feed'},{'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': 'updated'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'following'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'filter_folder'},{'id': '16', 'type': 'string', 'children': [], 'value': '""'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '19', 'type': 'string', 'children': [], 'value': '"updated"'},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'nid'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '34', '39', '77', '101']},{'id': '24', 'type': 'assert_statement', 'children': ['25']},{'id': '25', 'type': 'comparison_operator', 'children': ['26', '33'], 'value': '=='},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'list', 'children': ['30', '31', '32'], 'value': '[updated, following, folder]'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'updated'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'following'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '33', 'type': 'integer', 'children': [], 'value': '1'},{'id': '34', 'type': 'if_statement', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'assert_statement', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'filter_folder'},{'id': '39', 'type': 'if_statement', 'children': ['40', '41', '51', '63']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'updated'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'filter_type'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'updated'},{'id': '50', 'type': 'integer', 'children': [], 'value': '1'},{'id': '51', 'type': 'elif_clause', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'following'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'filter_type'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'following'},{'id': '62', 'type': 'integer', 'children': [], 'value': '1'},{'id': '63', 'type': 'else_clause', 'children': ['64']},{'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': 'filter_type'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '70', 'type': 'argument_list', 'children': ['71', '74']},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'folder'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'filter_folder'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'filter_folder'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'r'},{'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': 'request'},{'id': '84', 'type': 'argument_list', 'children': ['85', '88', '91']},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'nid'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'nid'},{'id': '88', 'type': 'keyword_argument', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '90', 'type': 'string', 'children': [], 'value': '"network.filter_feed"'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '95', 'type': 'argument_list', 'children': ['96', '99']},{'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '99', 'type': 'dictionary_splat', 'children': ['100']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'filter_type'},{'id': '101', 'type': 'return_statement', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_handle_error'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '108', 'type': 'string', 'children': [], 'value': '"Could not retrieve filtered feed."'} | def filter_feed(self, updated=False, following=False, folder=False,
filter_folder="", sort="updated", nid=None):
assert sum([updated, following, folder]) == 1
if folder:
assert filter_folder
if updated:
filter_type = dict(updated=1)
elif following:
filter_type = dict(following=1)
else:
filter_type = dict(folder=1, filter_folder=filter_folder)
r = self.request(
nid=nid,
method="network.filter_feed",
data=dict(
sort=sort,
**filter_type
)
)
return self._handle_error(r, "Could not retrieve filtered feed.") |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_dataset'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '6', 'type': 'block', 'children': ['7', '11', '19', '216']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'dataset_path'},{'id': '14', 'type': 'binary_operator', 'children': ['15', '18'], 'value': '+'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'base_dataset_path'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '19', 'type': 'if_statement', 'children': ['20', '25']},{'id': '20', 'type': 'not_operator', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dataset_path'},{'id': '25', 'type': 'block', 'children': ['26', '30', '184']},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'was_error'},{'id': '29', 'type': 'False', 'children': []},{'id': '30', 'type': 'for_statement', 'children': ['31', '32', '36']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'integer', 'children': [], 'value': '5'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'if_statement', 'children': ['38', '45']},{'id': '38', 'type': 'boolean_operator', 'children': ['39', '42'], 'value': 'or'},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': '=='},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'iteration'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'was_error'},{'id': '44', 'type': 'True', 'children': []},{'id': '45', 'type': 'block', 'children': ['46', '52', '117']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'zip_path'},{'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '+'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'dataset_path'},{'id': '51', 'type': 'string', 'children': [], 'value': '".zip"'},{'id': '52', 'type': 'if_statement', 'children': ['53', '58']},{'id': '53', 'type': 'not_operator', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'zip_path'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'try_statement', 'children': ['60', '98']},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'with_statement', 'children': ['62', '82']},{'id': '62', 'type': 'with_clause', 'children': ['63']},{'id': '63', 'type': 'with_item', 'children': ['64']},{'id': '64', 'type': 'as_pattern', 'children': ['65', '80']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'DLProgress'},{'id': '67', 'type': 'argument_list', 'children': ['68', '71', '74', '77']},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'unit'},{'id': '70', 'type': 'string', 'children': [], 'value': "'B'"},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'unit_scale'},{'id': '73', 'type': 'True', 'children': []},{'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'miniters'},{'id': '76', 'type': 'integer', 'children': [], 'value': '1'},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '80', 'type': 'as_pattern_target', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'pbar'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'urlretrieve'},{'id': '86', 'type': 'argument_list', 'children': ['87', '94', '95']},{'id': '87', 'type': 'subscript', 'children': ['88', '93']},{'id': '88', 'type': 'subscript', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '93', 'type': 'string', 'children': [], 'value': '"url"'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'zip_path'},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'pbar'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '98', 'type': 'except_clause', 'children': ['99', '103']},{'id': '99', 'type': 'as_pattern', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '101', 'type': 'as_pattern_target', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '103', 'type': 'block', 'children': ['104', '113']},{'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']},{'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '%'},{'id': '109', 'type': 'string', 'children': [], 'value': '"Error downloading %s: %s"'},{'id': '110', 'type': 'tuple', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'was_error'},{'id': '116', 'type': 'True', 'children': []},{'id': '117', 'type': 'if_statement', 'children': ['118', '123']},{'id': '118', 'type': 'not_operator', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'dataset_path'},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'try_statement', 'children': ['125', '154']},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'with_statement', 'children': ['127', '138']},{'id': '127', 'type': 'with_clause', 'children': ['128']},{'id': '128', 'type': 'with_item', 'children': ['129']},{'id': '129', 'type': 'as_pattern', 'children': ['130', '136']},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'zipfile'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'ZipFile'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'zip_path'},{'id': '136', 'type': 'as_pattern_target', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'zip_archive'},{'id': '138', 'type': 'block', 'children': ['139', '148']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'zip_archive'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'extractall'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'dataset_path'},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'zip_archive'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'except_clause', 'children': ['155', '159']},{'id': '155', 'type': 'as_pattern', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '157', 'type': 'as_pattern_target', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '159', 'type': 'block', 'children': ['160', '169', '180']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'binary_operator', 'children': ['165', '166'], 'value': '%'},{'id': '165', 'type': 'string', 'children': [], 'value': '"Error unzipping %s: %s"'},{'id': '166', 'type': 'tuple', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'zip_path'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'ex'},{'id': '169', 'type': 'try_statement', 'children': ['170', '176']},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'zip_path'},{'id': '176', 'type': 'except_clause', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'FileNotFoundError'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'pass_statement', 'children': []},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'was_error'},{'id': '183', 'type': 'True', 'children': []},{'id': '184', 'type': 'if_statement', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'was_error'},{'id': '186', 'type': 'block', 'children': ['187', '192', '205', '212']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'string', 'children': [], 'value': '"\\nThis recognizer is trained by the CASIA handwriting database."'},{'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']},{'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '%'},{'id': '197', 'type': 'string', 'children': [], 'value': '"If the download doesn\'t work, you can get the files at %s"'},{'id': '198', 'type': 'subscript', 'children': ['199', '204']},{'id': '199', 'type': 'subscript', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '204', 'type': 'string', 'children': [], 'value': '"url"'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'concatenated_string', 'children': ['210', '211']},{'id': '210', 'type': 'string', 'children': [], 'value': '"If you have download problems, "'},{'id': '211', 'type': 'string', 'children': [], 'value': '"wget may be effective at downloading because of download resuming."'},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '215', 'type': 'False', 'children': []},{'id': '216', 'type': 'return_statement', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'success'} | def get_dataset(self, dataset):
success = True
dataset_path = self.base_dataset_path + dataset
if not isdir(dataset_path):
was_error = False
for iteration in range(5):
if iteration == 0 or was_error is True:
zip_path = dataset_path + ".zip"
if not isfile(zip_path):
try:
with DLProgress(unit='B', unit_scale=True, miniters=1, desc=dataset) as pbar:
urlretrieve(self.datasets[dataset]["url"], zip_path, pbar.hook)
except Exception as ex:
print("Error downloading %s: %s" % (dataset, ex))
was_error = True
if not isdir(dataset_path):
try:
with zipfile.ZipFile(zip_path) as zip_archive:
zip_archive.extractall(path=dataset_path)
zip_archive.close()
except Exception as ex:
print("Error unzipping %s: %s" % (zip_path, ex))
try:
remove(zip_path)
except FileNotFoundError:
pass
was_error = True
if was_error:
print("\nThis recognizer is trained by the CASIA handwriting database.")
print("If the download doesn't work, you can get the files at %s" % self.datasets[dataset]["url"])
print("If you have download problems, "
"wget may be effective at downloading because of download resuming.")
success = False
return success |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'install'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '27', '30']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '6', 'type': 'True', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'verbose_destination'},{'id': '9', 'type': 'conditional_expression', 'children': ['10', '17', '24'], 'value': 'if'},{'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': 'sys'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '__stderr__'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fileno'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '19', 'type': 'argument_list', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '22', 'type': 'identifier', 'children': [], 'value': '__stderr__'},{'id': '23', 'type': 'string', 'children': [], 'value': "'fileno'"},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '__stderr__'},{'id': '27', 'type': 'default_parameter', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'strict'},{'id': '29', 'type': 'True', 'children': []},{'id': '30', 'type': 'dictionary_splat_pattern', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '32', 'type': 'block', 'children': ['33', '35', '75', '83', '91']},{'id': '33', 'type': 'global_statement', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_MANHOLE'},{'id': '35', 'type': 'with_statement', 'children': ['36', '39']},{'id': '36', 'type': 'with_clause', 'children': ['37']},{'id': '37', 'type': 'with_item', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_LOCK'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'if_statement', 'children': ['41', '44', '51']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_MANHOLE'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_MANHOLE'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'Manhole'},{'id': '50', 'type': 'argument_list', 'children': []},{'id': '51', 'type': 'else_clause', 'children': ['52']},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'if_statement', 'children': ['54', '55', '61']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'strict'},{'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': 'AlreadyInstalled'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'string', 'children': [], 'value': '"Manhole already installed!"'},{'id': '61', 'type': 'else_clause', 'children': ['62']},{'id': '62', 'type': 'block', 'children': ['63', '69']},{'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': '_LOG'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '68', 'type': 'argument_list', 'children': []},{'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': '_MANHOLE'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'release'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': '_LOG'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'configure'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'verbose_destination'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': '_MANHOLE'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'configure'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'dictionary_splat', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '91', 'type': 'return_statement', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': '_MANHOLE'} | def install(verbose=True,
verbose_destination=sys.__stderr__.fileno() if hasattr(sys.__stderr__, 'fileno') else sys.__stderr__,
strict=True,
**kwargs):
global _MANHOLE
with _LOCK:
if _MANHOLE is None:
_MANHOLE = Manhole()
else:
if strict:
raise AlreadyInstalled("Manhole already installed!")
else:
_LOG.release()
_MANHOLE.release()
_LOG.configure(verbose, verbose_destination)
_MANHOLE.configure(**kwargs)
return _MANHOLE |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '37']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'update'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25', '28', '31', '34']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'alert_condition_nrql_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'policy_id'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'threshold_type'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'since_value'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'expected_groups'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'value_function'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'runbook_url'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ignore_overlap'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'default_parameter', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'enabled'},{'id': '36', 'type': 'True', 'children': []},{'id': '37', 'type': 'block', 'children': ['38', '47', '51', '72', '90', '144', '164', '192', '220', '248', '276', '360']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'conditions_nrql_dict'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'policy_id'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'for_statement', 'children': ['52', '53', '56']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'condition'},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'conditions_nrql_dict'},{'id': '55', 'type': 'string', 'children': [], 'value': "'nrql_conditions'"},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'if_statement', 'children': ['58', '66']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '65'], 'value': '=='},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'condition'},{'id': '64', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'alert_condition_nrql_id'},{'id': '66', 'type': 'block', 'children': ['67', '71']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'condition'},{'id': '71', 'type': 'break_statement', 'children': []},{'id': '72', 'type': 'if_statement', 'children': ['73', '76']},{'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'is'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '75', 'type': 'None', 'children': []},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'raise_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'NoEntityException'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '87']},{'id': '82', 'type': 'attribute', 'children': ['83', '86']},{'id': '83', 'type': 'concatenated_string', 'children': ['84', '85']},{'id': '84', 'type': 'string', 'children': [], 'value': "'Target alert condition nrql is not included in that policy.'"},{'id': '85', 'type': 'string', 'children': [], 'value': "'policy_id: {}, alert_condition_nrql_id {}'"},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'policy_id'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'alert_condition_nrql_id'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '93', 'type': 'dictionary', 'children': ['94']},{'id': '94', 'type': 'pair', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '96', 'type': 'dictionary', 'children': ['97', '104', '109', '116', '123']},{'id': '97', 'type': 'pair', 'children': ['98', '99']},{'id': '98', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '99', 'type': 'boolean_operator', 'children': ['100', '101'], 'value': 'or'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'threshold_type'},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '103', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '104', 'type': 'pair', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': "'enabled'"},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '108', 'type': 'string', 'children': [], 'value': "'enabled'"},{'id': '109', 'type': 'pair', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '111', 'type': 'boolean_operator', 'children': ['112', '113'], 'value': 'or'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '115', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '116', 'type': 'pair', 'children': ['117', '118']},{'id': '117', 'type': 'string', 'children': [], 'value': "'terms'"},{'id': '118', 'type': 'boolean_operator', 'children': ['119', '120'], 'value': 'or'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '120', 'type': 'subscript', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '122', 'type': 'string', 'children': [], 'value': "'terms'"},{'id': '123', 'type': 'pair', 'children': ['124', '125']},{'id': '124', 'type': 'string', 'children': [], 'value': "'nrql'"},{'id': '125', 'type': 'dictionary', 'children': ['126', '135']},{'id': '126', 'type': 'pair', 'children': ['127', '128']},{'id': '127', 'type': 'string', 'children': [], 'value': "'query'"},{'id': '128', 'type': 'boolean_operator', 'children': ['129', '130'], 'value': 'or'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '130', 'type': 'subscript', 'children': ['131', '134']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '133', 'type': 'string', 'children': [], 'value': "'nrql'"},{'id': '134', 'type': 'string', 'children': [], 'value': "'query'"},{'id': '135', 'type': 'pair', 'children': ['136', '137']},{'id': '136', 'type': 'string', 'children': [], 'value': "'since_value'"},{'id': '137', 'type': 'boolean_operator', 'children': ['138', '139'], 'value': 'or'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'since_value'},{'id': '139', 'type': 'subscript', 'children': ['140', '143']},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '142', 'type': 'string', 'children': [], 'value': "'nrql'"},{'id': '143', 'type': 'string', 'children': [], 'value': "'since_value'"},{'id': '144', 'type': 'if_statement', 'children': ['145', '148']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'is'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'enabled'},{'id': '147', 'type': 'None', 'children': []},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '156']},{'id': '151', 'type': 'subscript', 'children': ['152', '155']},{'id': '152', 'type': 'subscript', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '154', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '155', 'type': 'string', 'children': [], 'value': "'enabled'"},{'id': '156', 'type': 'call', 'children': ['157', '163']},{'id': '157', 'type': 'attribute', 'children': ['158', '162']},{'id': '158', 'type': 'call', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'enabled'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '163', 'type': 'argument_list', 'children': []},{'id': '164', 'type': 'if_statement', 'children': ['165', '168', '177']},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': 'is'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'runbook_url'},{'id': '167', 'type': 'None', 'children': []},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '176']},{'id': '171', 'type': 'subscript', 'children': ['172', '175']},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '174', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '175', 'type': 'string', 'children': [], 'value': "'runbook_url'"},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'runbook_url'},{'id': '177', 'type': 'elif_clause', 'children': ['178', '181']},{'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': 'in'},{'id': '179', 'type': 'string', 'children': [], 'value': "'runbook_url'"},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '189']},{'id': '184', 'type': 'subscript', 'children': ['185', '188']},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '187', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '188', 'type': 'string', 'children': [], 'value': "'runbook_url'"},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '191', 'type': 'string', 'children': [], 'value': "'runbook_url'"},{'id': '192', 'type': 'if_statement', 'children': ['193', '196', '205']},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': 'is'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'expected_groups'},{'id': '195', 'type': 'None', 'children': []},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '204']},{'id': '199', 'type': 'subscript', 'children': ['200', '203']},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '202', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '203', 'type': 'string', 'children': [], 'value': "'expected_groups'"},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'expected_groups'},{'id': '205', 'type': 'elif_clause', 'children': ['206', '209']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': 'in'},{'id': '207', 'type': 'string', 'children': [], 'value': "'expected_groups'"},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '217']},{'id': '212', 'type': 'subscript', 'children': ['213', '216']},{'id': '213', 'type': 'subscript', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '215', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '216', 'type': 'string', 'children': [], 'value': "'expected_groups'"},{'id': '217', 'type': 'subscript', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '219', 'type': 'string', 'children': [], 'value': "'expected_groups'"},{'id': '220', 'type': 'if_statement', 'children': ['221', '224', '233']},{'id': '221', 'type': 'comparison_operator', 'children': ['222', '223'], 'value': 'is'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'ignore_overlap'},{'id': '223', 'type': 'None', 'children': []},{'id': '224', 'type': 'block', 'children': ['225']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '232']},{'id': '227', 'type': 'subscript', 'children': ['228', '231']},{'id': '228', 'type': 'subscript', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '230', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '231', 'type': 'string', 'children': [], 'value': "'ignore_overlap'"},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'ignore_overlap'},{'id': '233', 'type': 'elif_clause', 'children': ['234', '237']},{'id': '234', 'type': 'comparison_operator', 'children': ['235', '236'], 'value': 'in'},{'id': '235', 'type': 'string', 'children': [], 'value': "'ignore_overlap'"},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '237', 'type': 'block', 'children': ['238']},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '245']},{'id': '240', 'type': 'subscript', 'children': ['241', '244']},{'id': '241', 'type': 'subscript', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '243', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '244', 'type': 'string', 'children': [], 'value': "'ignore_overlap'"},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '247', 'type': 'string', 'children': [], 'value': "'ignore_overlap'"},{'id': '248', 'type': 'if_statement', 'children': ['249', '252', '261']},{'id': '249', 'type': 'comparison_operator', 'children': ['250', '251'], 'value': 'is'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'value_function'},{'id': '251', 'type': 'None', 'children': []},{'id': '252', 'type': 'block', 'children': ['253']},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '260']},{'id': '255', 'type': 'subscript', 'children': ['256', '259']},{'id': '256', 'type': 'subscript', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '258', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '259', 'type': 'string', 'children': [], 'value': "'value_function'"},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'value_function'},{'id': '261', 'type': 'elif_clause', 'children': ['262', '265']},{'id': '262', 'type': 'comparison_operator', 'children': ['263', '264'], 'value': 'in'},{'id': '263', 'type': 'string', 'children': [], 'value': "'value_function'"},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '265', 'type': 'block', 'children': ['266']},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '273']},{'id': '268', 'type': 'subscript', 'children': ['269', '272']},{'id': '269', 'type': 'subscript', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '271', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '272', 'type': 'string', 'children': [], 'value': "'value_function'"},{'id': '273', 'type': 'subscript', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'target_condition_nrql'},{'id': '275', 'type': 'string', 'children': [], 'value': "'value_function'"},{'id': '276', 'type': 'if_statement', 'children': ['277', '284', '317']},{'id': '277', 'type': 'comparison_operator', 'children': ['278', '283'], 'value': '=='},{'id': '278', 'type': 'subscript', 'children': ['279', '282']},{'id': '279', 'type': 'subscript', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '281', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '282', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '283', 'type': 'string', 'children': [], 'value': "'static'"},{'id': '284', 'type': 'block', 'children': ['285', '297', '307']},{'id': '285', 'type': 'if_statement', 'children': ['286', '291']},{'id': '286', 'type': 'comparison_operator', 'children': ['287', '288'], 'value': 'not'},{'id': '287', 'type': 'string', 'children': [], 'value': "'value_function'"},{'id': '288', 'type': 'subscript', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '290', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '291', 'type': 'block', 'children': ['292']},{'id': '292', 'type': 'raise_statement', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'ConfigurationException'},{'id': '295', 'type': 'argument_list', 'children': ['296']},{'id': '296', 'type': 'string', 'children': [], 'value': "'Alert is set as static but no value_function config specified'"},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'call', 'children': ['299', '304']},{'id': '299', 'type': 'attribute', 'children': ['300', '303']},{'id': '300', 'type': 'subscript', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '302', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '304', 'type': 'argument_list', 'children': ['305', '306']},{'id': '305', 'type': 'string', 'children': [], 'value': "'expected_groups'"},{'id': '306', 'type': 'None', 'children': []},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '314']},{'id': '309', 'type': 'attribute', 'children': ['310', '313']},{'id': '310', 'type': 'subscript', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '312', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '314', 'type': 'argument_list', 'children': ['315', '316']},{'id': '315', 'type': 'string', 'children': [], 'value': "'ignore_overlap'"},{'id': '316', 'type': 'None', 'children': []},{'id': '317', 'type': 'elif_clause', 'children': ['318', '325']},{'id': '318', 'type': 'comparison_operator', 'children': ['319', '324'], 'value': '=='},{'id': '319', 'type': 'subscript', 'children': ['320', '323']},{'id': '320', 'type': 'subscript', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '322', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '323', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '324', 'type': 'string', 'children': [], 'value': "'outlier'"},{'id': '325', 'type': 'block', 'children': ['326', '338', '350']},{'id': '326', 'type': 'if_statement', 'children': ['327', '332']},{'id': '327', 'type': 'comparison_operator', 'children': ['328', '329'], 'value': 'not'},{'id': '328', 'type': 'string', 'children': [], 'value': "'expected_groups'"},{'id': '329', 'type': 'subscript', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '331', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '332', 'type': 'block', 'children': ['333']},{'id': '333', 'type': 'raise_statement', 'children': ['334']},{'id': '334', 'type': 'call', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'ConfigurationException'},{'id': '336', 'type': 'argument_list', 'children': ['337']},{'id': '337', 'type': 'string', 'children': [], 'value': "'Alert is set as outlier but expected_groups config is not specified'"},{'id': '338', 'type': 'if_statement', 'children': ['339', '344']},{'id': '339', 'type': 'comparison_operator', 'children': ['340', '341'], 'value': 'not'},{'id': '340', 'type': 'string', 'children': [], 'value': "'ignore_overlap'"},{'id': '341', 'type': 'subscript', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '343', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '344', 'type': 'block', 'children': ['345']},{'id': '345', 'type': 'raise_statement', 'children': ['346']},{'id': '346', 'type': 'call', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'ConfigurationException'},{'id': '348', 'type': 'argument_list', 'children': ['349']},{'id': '349', 'type': 'string', 'children': [], 'value': "'Alert is set as outlier but ignore_overlap config is not specified'"},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'call', 'children': ['352', '357']},{'id': '352', 'type': 'attribute', 'children': ['353', '356']},{'id': '353', 'type': 'subscript', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '355', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '357', 'type': 'argument_list', 'children': ['358', '359']},{'id': '358', 'type': 'string', 'children': [], 'value': "'value_function'"},{'id': '359', 'type': 'None', 'children': []},{'id': '360', 'type': 'return_statement', 'children': ['361']},{'id': '361', 'type': 'call', 'children': ['362', '365']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '364', 'type': 'identifier', 'children': [], 'value': '_put'},{'id': '365', 'type': 'argument_list', 'children': ['366', '377', '382']},{'id': '366', 'type': 'keyword_argument', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '368', 'type': 'call', 'children': ['369', '372']},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'string', 'children': [], 'value': "'{0}alerts_nrql_conditions/{1}.json'"},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '372', 'type': 'argument_list', 'children': ['373', '376']},{'id': '373', 'type': 'attribute', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'alert_condition_nrql_id'},{'id': '377', 'type': 'keyword_argument', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '379', 'type': 'attribute', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '382', 'type': 'keyword_argument', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'data'} | def update(
self, alert_condition_nrql_id, policy_id, name=None, threshold_type=None, query=None,
since_value=None, terms=None, expected_groups=None, value_function=None,
runbook_url=None, ignore_overlap=None, enabled=True):
conditions_nrql_dict = self.list(policy_id)
target_condition_nrql = None
for condition in conditions_nrql_dict['nrql_conditions']:
if int(condition['id']) == alert_condition_nrql_id:
target_condition_nrql = condition
break
if target_condition_nrql is None:
raise NoEntityException(
'Target alert condition nrql is not included in that policy.'
'policy_id: {}, alert_condition_nrql_id {}'.format(
policy_id,
alert_condition_nrql_id
)
)
data = {
'nrql_condition': {
'type': threshold_type or target_condition_nrql['type'],
'enabled': target_condition_nrql['enabled'],
'name': name or target_condition_nrql['name'],
'terms': terms or target_condition_nrql['terms'],
'nrql': {
'query': query or target_condition_nrql['nrql']['query'],
'since_value': since_value or target_condition_nrql['nrql']['since_value'],
}
}
}
if enabled is not None:
data['nrql_condition']['enabled'] = str(enabled).lower()
if runbook_url is not None:
data['nrql_condition']['runbook_url'] = runbook_url
elif 'runbook_url' in target_condition_nrql:
data['nrql_condition']['runbook_url'] = target_condition_nrql['runbook_url']
if expected_groups is not None:
data['nrql_condition']['expected_groups'] = expected_groups
elif 'expected_groups' in target_condition_nrql:
data['nrql_condition']['expected_groups'] = target_condition_nrql['expected_groups']
if ignore_overlap is not None:
data['nrql_condition']['ignore_overlap'] = ignore_overlap
elif 'ignore_overlap' in target_condition_nrql:
data['nrql_condition']['ignore_overlap'] = target_condition_nrql['ignore_overlap']
if value_function is not None:
data['nrql_condition']['value_function'] = value_function
elif 'value_function' in target_condition_nrql:
data['nrql_condition']['value_function'] = target_condition_nrql['value_function']
if data['nrql_condition']['type'] == 'static':
if 'value_function' not in data['nrql_condition']:
raise ConfigurationException(
'Alert is set as static but no value_function config specified'
)
data['nrql_condition'].pop('expected_groups', None)
data['nrql_condition'].pop('ignore_overlap', None)
elif data['nrql_condition']['type'] == 'outlier':
if 'expected_groups' not in data['nrql_condition']:
raise ConfigurationException(
'Alert is set as outlier but expected_groups config is not specified'
)
if 'ignore_overlap' not in data['nrql_condition']:
raise ConfigurationException(
'Alert is set as outlier but ignore_overlap config is not specified'
)
data['nrql_condition'].pop('value_function', None)
return self._put(
url='{0}alerts_nrql_conditions/{1}.json'.format(self.URL, alert_condition_nrql_id),
headers=self.headers,
data=data
) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'create'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '14', '17', '20', '23']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'policy_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'threshold_type'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'since_value'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'expected_groups'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'value_function'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'runbook_url'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ignore_overlap'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'enabled'},{'id': '25', 'type': 'True', 'children': []},{'id': '26', 'type': 'block', 'children': ['27', '55', '68', '81', '94', '107', '191']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '30', 'type': 'dictionary', 'children': ['31']},{'id': '31', 'type': 'pair', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '33', 'type': 'dictionary', 'children': ['34', '37', '40', '43', '46']},{'id': '34', 'type': 'pair', 'children': ['35', '36']},{'id': '35', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'threshold_type'},{'id': '37', 'type': 'pair', 'children': ['38', '39']},{'id': '38', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '40', 'type': 'pair', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': "'enabled'"},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'enabled'},{'id': '43', 'type': 'pair', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "'terms'"},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '46', 'type': 'pair', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': "'nrql'"},{'id': '48', 'type': 'dictionary', 'children': ['49', '52']},{'id': '49', 'type': 'pair', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'query'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '52', 'type': 'pair', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "'since_value'"},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'since_value'},{'id': '55', 'type': 'if_statement', 'children': ['56', '59']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'is'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'runbook_url'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '67']},{'id': '62', 'type': 'subscript', 'children': ['63', '66']},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '65', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '66', 'type': 'string', 'children': [], 'value': "'runbook_url'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'runbook_url'},{'id': '68', 'type': 'if_statement', 'children': ['69', '72']},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'is'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'expected_groups'},{'id': '71', 'type': 'None', 'children': []},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '80']},{'id': '75', 'type': 'subscript', 'children': ['76', '79']},{'id': '76', 'type': 'subscript', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '78', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '79', 'type': 'string', 'children': [], 'value': "'expected_groups'"},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'expected_groups'},{'id': '81', 'type': 'if_statement', 'children': ['82', '85']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'is'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ignore_overlap'},{'id': '84', 'type': 'None', 'children': []},{'id': '85', 'type': 'block', 'children': ['86']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '93']},{'id': '88', 'type': 'subscript', 'children': ['89', '92']},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '91', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '92', 'type': 'string', 'children': [], 'value': "'ignore_overlap'"},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'ignore_overlap'},{'id': '94', 'type': 'if_statement', 'children': ['95', '98']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'is'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'value_function'},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '106']},{'id': '101', 'type': 'subscript', 'children': ['102', '105']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '104', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '105', 'type': 'string', 'children': [], 'value': "'value_function'"},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'value_function'},{'id': '107', 'type': 'if_statement', 'children': ['108', '115', '148']},{'id': '108', 'type': 'comparison_operator', 'children': ['109', '114'], 'value': '=='},{'id': '109', 'type': 'subscript', 'children': ['110', '113']},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '112', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '113', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '114', 'type': 'string', 'children': [], 'value': "'static'"},{'id': '115', 'type': 'block', 'children': ['116', '128', '138']},{'id': '116', 'type': 'if_statement', 'children': ['117', '122']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': 'not'},{'id': '118', 'type': 'string', 'children': [], 'value': "'value_function'"},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '121', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'raise_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'ConfigurationException'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'string', 'children': [], 'value': "'Alert is set as static but no value_function config specified'"},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '135']},{'id': '130', 'type': 'attribute', 'children': ['131', '134']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '133', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137']},{'id': '136', 'type': 'string', 'children': [], 'value': "'expected_groups'"},{'id': '137', 'type': 'None', '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': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '143', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147']},{'id': '146', 'type': 'string', 'children': [], 'value': "'ignore_overlap'"},{'id': '147', 'type': 'None', 'children': []},{'id': '148', 'type': 'elif_clause', 'children': ['149', '156']},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '155'], 'value': '=='},{'id': '150', 'type': 'subscript', 'children': ['151', '154']},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '153', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '154', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '155', 'type': 'string', 'children': [], 'value': "'outlier'"},{'id': '156', 'type': 'block', 'children': ['157', '169', '181']},{'id': '157', 'type': 'if_statement', 'children': ['158', '163']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': 'not'},{'id': '159', 'type': 'string', 'children': [], 'value': "'expected_groups'"},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '162', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'raise_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'ConfigurationException'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'string', 'children': [], 'value': "'Alert is set as outlier but expected_groups config is not specified'"},{'id': '169', 'type': 'if_statement', 'children': ['170', '175']},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': 'not'},{'id': '171', 'type': 'string', 'children': [], 'value': "'ignore_overlap'"},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '174', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'raise_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'ConfigurationException'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'string', 'children': [], 'value': "'Alert is set as outlier but ignore_overlap config is not specified'"},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '188']},{'id': '183', 'type': 'attribute', 'children': ['184', '187']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '186', 'type': 'string', 'children': [], 'value': "'nrql_condition'"},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '188', 'type': 'argument_list', 'children': ['189', '190']},{'id': '189', 'type': 'string', 'children': [], 'value': "'value_function'"},{'id': '190', 'type': 'None', 'children': []},{'id': '191', 'type': 'return_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '195', 'type': 'identifier', 'children': [], 'value': '_post'},{'id': '196', 'type': 'argument_list', 'children': ['197', '208', '213']},{'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'string', 'children': [], 'value': "'{0}alerts_nrql_conditions/policies/{1}.json'"},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '203', 'type': 'argument_list', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'policy_id'},{'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '213', 'type': 'keyword_argument', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'data'} | def create(
self, policy_id, name, threshold_type, query, since_value, terms,
expected_groups=None, value_function=None, runbook_url=None,
ignore_overlap=None, enabled=True):
data = {
'nrql_condition': {
'type': threshold_type,
'name': name,
'enabled': enabled,
'terms': terms,
'nrql': {
'query': query,
'since_value': since_value
}
}
}
if runbook_url is not None:
data['nrql_condition']['runbook_url'] = runbook_url
if expected_groups is not None:
data['nrql_condition']['expected_groups'] = expected_groups
if ignore_overlap is not None:
data['nrql_condition']['ignore_overlap'] = ignore_overlap
if value_function is not None:
data['nrql_condition']['value_function'] = value_function
if data['nrql_condition']['type'] == 'static':
if 'value_function' not in data['nrql_condition']:
raise ConfigurationException(
'Alert is set as static but no value_function config specified'
)
data['nrql_condition'].pop('expected_groups', None)
data['nrql_condition'].pop('ignore_overlap', None)
elif data['nrql_condition']['type'] == 'outlier':
if 'expected_groups' not in data['nrql_condition']:
raise ConfigurationException(
'Alert is set as outlier but expected_groups config is not specified'
)
if 'ignore_overlap' not in data['nrql_condition']:
raise ConfigurationException(
'Alert is set as outlier but ignore_overlap config is not specified'
)
data['nrql_condition'].pop('value_function', None)
return self._post(
url='{0}alerts_nrql_conditions/policies/{1}.json'.format(self.URL, policy_id),
headers=self.headers,
data=data
) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '34']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'update'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25', '28', '31']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'alert_condition_id'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'policy_id'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'condition_scope'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'default_parameter', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'entities'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'metric'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'runbook_url'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'default_parameter', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'default_parameter', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'user_defined'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'default_parameter', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'enabled'},{'id': '33', 'type': 'None', 'children': []},{'id': '34', 'type': 'block', 'children': ['35', '44', '48', '69', '87', '143', '163', '205']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'conditions_dict'},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'policy_id'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'target_condition'},{'id': '47', 'type': 'None', 'children': []},{'id': '48', 'type': 'for_statement', 'children': ['49', '50', '53']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'condition'},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'conditions_dict'},{'id': '52', 'type': 'string', 'children': [], 'value': "'conditions'"},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'if_statement', 'children': ['55', '63']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '62'], 'value': '=='},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'condition'},{'id': '61', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'alert_condition_id'},{'id': '63', 'type': 'block', 'children': ['64', '68']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'target_condition'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'condition'},{'id': '68', 'type': 'break_statement', 'children': []},{'id': '69', 'type': 'if_statement', 'children': ['70', '73']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'is'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'target_condition'},{'id': '72', 'type': 'None', 'children': []},{'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': 'NoEntityException'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '84']},{'id': '79', 'type': 'attribute', 'children': ['80', '83']},{'id': '80', 'type': 'concatenated_string', 'children': ['81', '82']},{'id': '81', 'type': 'string', 'children': [], 'value': "'Target alert condition is not included in that policy.'"},{'id': '82', 'type': 'string', 'children': [], 'value': "'policy_id: {}, alert_condition_id {}'"},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'policy_id'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'alert_condition_id'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '90', 'type': 'dictionary', 'children': ['91']},{'id': '91', 'type': 'pair', 'children': ['92', '93']},{'id': '92', 'type': 'string', 'children': [], 'value': "'condition'"},{'id': '93', 'type': 'dictionary', 'children': ['94', '101', '108', '115', '122', '129', '136']},{'id': '94', 'type': 'pair', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '96', 'type': 'boolean_operator', 'children': ['97', '98'], 'value': 'or'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'target_condition'},{'id': '100', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '101', 'type': 'pair', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '103', 'type': 'boolean_operator', 'children': ['104', '105'], 'value': 'or'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'target_condition'},{'id': '107', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '108', 'type': 'pair', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': "'entities'"},{'id': '110', 'type': 'boolean_operator', 'children': ['111', '112'], 'value': 'or'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'entities'},{'id': '112', 'type': 'subscript', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'target_condition'},{'id': '114', 'type': 'string', 'children': [], 'value': "'entities'"},{'id': '115', 'type': 'pair', 'children': ['116', '117']},{'id': '116', 'type': 'string', 'children': [], 'value': "'condition_scope'"},{'id': '117', 'type': 'boolean_operator', 'children': ['118', '119'], 'value': 'or'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'condition_scope'},{'id': '119', 'type': 'subscript', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'target_condition'},{'id': '121', 'type': 'string', 'children': [], 'value': "'condition_scope'"},{'id': '122', 'type': 'pair', 'children': ['123', '124']},{'id': '123', 'type': 'string', 'children': [], 'value': "'terms'"},{'id': '124', 'type': 'boolean_operator', 'children': ['125', '126'], 'value': 'or'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'terms'},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'target_condition'},{'id': '128', 'type': 'string', 'children': [], 'value': "'terms'"},{'id': '129', 'type': 'pair', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': "'metric'"},{'id': '131', 'type': 'boolean_operator', 'children': ['132', '133'], 'value': 'or'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'metric'},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'target_condition'},{'id': '135', 'type': 'string', 'children': [], 'value': "'metric'"},{'id': '136', 'type': 'pair', 'children': ['137', '138']},{'id': '137', 'type': 'string', 'children': [], 'value': "'runbook_url'"},{'id': '138', 'type': 'boolean_operator', 'children': ['139', '140'], 'value': 'or'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'runbook_url'},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'target_condition'},{'id': '142', 'type': 'string', 'children': [], 'value': "'runbook_url'"},{'id': '143', 'type': 'if_statement', 'children': ['144', '147']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': 'is'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'enabled'},{'id': '146', 'type': 'None', 'children': []},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '155']},{'id': '150', 'type': 'subscript', 'children': ['151', '154']},{'id': '151', 'type': 'subscript', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '153', 'type': 'string', 'children': [], 'value': "'condition'"},{'id': '154', 'type': 'string', 'children': [], 'value': "'enabled'"},{'id': '155', 'type': 'call', 'children': ['156', '162']},{'id': '156', 'type': 'attribute', 'children': ['157', '161']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'enabled'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '162', 'type': 'argument_list', 'children': []},{'id': '163', 'type': 'if_statement', 'children': ['164', '171']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '170'], 'value': '=='},{'id': '165', 'type': 'subscript', 'children': ['166', '169']},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '168', 'type': 'string', 'children': [], 'value': "'condition'"},{'id': '169', 'type': 'string', 'children': [], 'value': "'metric'"},{'id': '170', 'type': 'string', 'children': [], 'value': "'user_defined'"},{'id': '171', 'type': 'block', 'children': ['172']},{'id': '172', 'type': 'if_statement', 'children': ['173', '174', '183', '198']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'user_defined'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '182']},{'id': '177', 'type': 'subscript', 'children': ['178', '181']},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '180', 'type': 'string', 'children': [], 'value': "'condition'"},{'id': '181', 'type': 'string', 'children': [], 'value': "'user_defined'"},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'user_defined'},{'id': '183', 'type': 'elif_clause', 'children': ['184', '187']},{'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': 'in'},{'id': '185', 'type': 'string', 'children': [], 'value': "'user_defined'"},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'target_condition'},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'assignment', 'children': ['190', '195']},{'id': '190', 'type': 'subscript', 'children': ['191', '194']},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '193', 'type': 'string', 'children': [], 'value': "'condition'"},{'id': '194', 'type': 'string', 'children': [], 'value': "'user_defined'"},{'id': '195', 'type': 'subscript', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'target_condition'},{'id': '197', 'type': 'string', 'children': [], 'value': "'user_defined'"},{'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', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'ConfigurationException'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'string', 'children': [], 'value': "'Metric is set as user_defined but no user_defined config specified'"},{'id': '205', 'type': 'return_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '209', 'type': 'identifier', 'children': [], 'value': '_put'},{'id': '210', 'type': 'argument_list', 'children': ['211', '222', '227']},{'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'string', 'children': [], 'value': "'{0}alerts_conditions/{1}.json'"},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '217', 'type': 'argument_list', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'URL'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'alert_condition_id'},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'data'} | def update(
self, alert_condition_id, policy_id,
type=None,
condition_scope=None,
name=None,
entities=None,
metric=None,
runbook_url=None,
terms=None,
user_defined=None,
enabled=None):
conditions_dict = self.list(policy_id)
target_condition = None
for condition in conditions_dict['conditions']:
if int(condition['id']) == alert_condition_id:
target_condition = condition
break
if target_condition is None:
raise NoEntityException(
'Target alert condition is not included in that policy.'
'policy_id: {}, alert_condition_id {}'.format(policy_id, alert_condition_id)
)
data = {
'condition': {
'type': type or target_condition['type'],
'name': name or target_condition['name'],
'entities': entities or target_condition['entities'],
'condition_scope': condition_scope or target_condition['condition_scope'],
'terms': terms or target_condition['terms'],
'metric': metric or target_condition['metric'],
'runbook_url': runbook_url or target_condition['runbook_url'],
}
}
if enabled is not None:
data['condition']['enabled'] = str(enabled).lower()
if data['condition']['metric'] == 'user_defined':
if user_defined:
data['condition']['user_defined'] = user_defined
elif 'user_defined' in target_condition:
data['condition']['user_defined'] = target_condition['user_defined']
else:
raise ConfigurationException(
'Metric is set as user_defined but no user_defined config specified'
)
return self._put(
url='{0}alerts_conditions/{1}.json'.format(self.URL, alert_condition_id),
headers=self.headers,
data=data
) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'operatorPrecedence'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '6', 'type': 'block', 'children': ['7', '13', '29', '49', '214', '218']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'expression'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'Forward'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '16', 'type': 'binary_operator', 'children': ['17', '18'], 'value': '|'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '18', 'type': 'binary_operator', 'children': ['19', '25'], 'value': '+'},{'id': '19', 'type': 'binary_operator', 'children': ['20', '24'], 'value': '+'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Suppress'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': "'('"},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'expression'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'Suppress'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'string', 'children': [], 'value': "')'"},{'id': '29', 'type': 'function_definition', 'children': ['30', '31', '41']},{'id': '30', 'type': 'function_name', 'children': [], 'value': 'parse_operator'},{'id': '31', 'type': 'parameters', 'children': ['32', '33', '34', '35', '38']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'arity'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'association'},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '40', 'type': 'None', 'children': []},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'return_statement', 'children': ['43']},{'id': '43', 'type': 'expression_list', 'children': ['44', '45', '46', '47', '48']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'arity'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'association'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '49', 'type': 'for_statement', 'children': ['50', '51', '52']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'operators'},{'id': '52', 'type': 'block', 'children': ['53', '66', '80', '96', '102', '191', '203', '210']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '61']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57', '58', '59', '60']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'arity'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'association'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'parse_operator'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'list_splat', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'op'},{'id': '66', 'type': 'if_statement', 'children': ['67', '74']},{'id': '67', 'type': 'boolean_operator', 'children': ['68', '71'], 'value': 'or'},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '<'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'arity'},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': '>'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'arity'},{'id': '73', 'type': 'integer', 'children': [], 'value': '2'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'raise_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': '"Arity must be unary (1) or binary (2)"'},{'id': '80', 'type': 'if_statement', 'children': ['81', '90']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'not'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'association'},{'id': '83', 'type': 'tuple', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'opAssoc'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'LEFT'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'opAssoc'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'RIGHT'},{'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': 'Exception'},{'id': '94', 'type': 'argument_list', 'children': ['95']},{'id': '95', 'type': 'string', 'children': [], 'value': '"Association must be LEFT or RIGHT"'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'Forward'},{'id': '101', 'type': 'argument_list', 'children': []},{'id': '102', 'type': 'if_statement', 'children': ['103', '108', '149']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'is'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'association'},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'opAssoc'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'LEFT'},{'id': '108', 'type': 'block', 'children': ['109', '119']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'new_last'},{'id': '112', 'type': 'conditional_expression', 'children': ['113', '117', '118'], 'value': 'if'},{'id': '113', 'type': '()', 'children': ['114']},{'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '|'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '119', 'type': 'if_statement', 'children': ['120', '123', '133']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '=='},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'arity'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'operator_expression'},{'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '+'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'new_last'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'OneOrMore'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '133', 'type': 'elif_clause', 'children': ['134', '137']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': '=='},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'arity'},{'id': '136', 'type': 'integer', 'children': [], 'value': '2'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'operator_expression'},{'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '+'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'OneOrMore'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '+'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'new_last'},{'id': '149', 'type': 'elif_clause', 'children': ['150', '155']},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': 'is'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'association'},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'opAssoc'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'RIGHT'},{'id': '155', 'type': 'block', 'children': ['156', '166']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'new_this'},{'id': '159', 'type': 'conditional_expression', 'children': ['160', '164', '165'], 'value': 'if'},{'id': '160', 'type': '()', 'children': ['161']},{'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '|'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'extra'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '166', 'type': 'if_statement', 'children': ['167', '170', '177']},{'id': '167', 'type': 'comparison_operator', 'children': ['168', '169'], 'value': '=='},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'arity'},{'id': '169', 'type': 'integer', 'children': [], 'value': '1'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'operator_expression'},{'id': '174', 'type': 'binary_operator', 'children': ['175', '176'], 'value': '+'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'expr'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'new_this'},{'id': '177', 'type': 'elif_clause', 'children': ['178', '181']},{'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': '=='},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'arity'},{'id': '180', 'type': 'integer', 'children': [], 'value': '2'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'operator_expression'},{'id': '185', 'type': 'binary_operator', 'children': ['186', '187'], 'value': '+'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '187', 'type': 'call', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'OneOrMore'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'new_this'},{'id': '191', 'type': 'if_statement', 'children': ['192', '195']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'is'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '194', 'type': 'None', 'children': []},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'operator_expression'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'setParseAction'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'augmented_assignment', 'children': ['205', '206'], 'value': '<<='},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '206', 'type': '()', 'children': ['207']},{'id': '207', 'type': 'binary_operator', 'children': ['208', '209'], 'value': '|'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'operator_expression'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'this'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'augmented_assignment', 'children': ['216', '217'], 'value': '<<='},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'expression'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '218', 'type': 'return_statement', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'expression'} | def operatorPrecedence(base, operators):
expression = Forward()
last = base | Suppress('(') + expression + Suppress(')')
def parse_operator(expr, arity, association, action=None, extra=None):
return expr, arity, association, action, extra
for op in operators:
expr, arity, association, action, extra = parse_operator(*op)
if arity < 1 or arity > 2:
raise Exception("Arity must be unary (1) or binary (2)")
if association not in (opAssoc.LEFT, opAssoc.RIGHT):
raise Exception("Association must be LEFT or RIGHT")
this = Forward()
if association is opAssoc.LEFT:
new_last = (last | extra) if extra else last
if arity == 1:
operator_expression = new_last + OneOrMore(expr)
elif arity == 2:
operator_expression = last + OneOrMore(expr + new_last)
elif association is opAssoc.RIGHT:
new_this = (this | extra) if extra else this
if arity == 1:
operator_expression = expr + new_this
elif arity == 2:
operator_expression = last + OneOrMore(new_this)
if action is not None:
operator_expression.setParseAction(action)
this <<= (operator_expression | last)
last = this
expression <<= last
return expression |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'readGraph'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'edgeList'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'nodeList'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'directed'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'idKey'},{'id': '13', 'type': 'string', 'children': [], 'value': "'ID'"},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'eSource'},{'id': '16', 'type': 'string', 'children': [], 'value': "'From'"},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'eDest'},{'id': '19', 'type': 'string', 'children': [], 'value': "'To'"},{'id': '20', 'type': 'block', 'children': ['21', '27', '48']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'progArgs'},{'id': '24', 'type': 'tuple', 'children': ['25', '26']},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'string', 'children': [], 'value': '"Starting to reading graphs"'},{'id': '27', 'type': 'if_statement', 'children': ['28', '31', '39']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'metaknowledge'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_MODE'},{'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': 'progKwargs'},{'id': '35', 'type': 'dictionary', 'children': ['36']},{'id': '36', 'type': 'pair', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'dummy'"},{'id': '38', 'type': 'False', 'children': []},{'id': '39', 'type': 'else_clause', 'children': ['40']},{'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': 'progKwargs'},{'id': '44', 'type': 'dictionary', 'children': ['45']},{'id': '45', 'type': 'pair', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'dummy'"},{'id': '47', 'type': 'True', 'children': []},{'id': '48', 'type': 'with_statement', 'children': ['49', '61']},{'id': '49', 'type': 'with_clause', 'children': ['50']},{'id': '50', 'type': 'with_item', 'children': ['51']},{'id': '51', 'type': 'as_pattern', 'children': ['52', '59']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_ProgressBar'},{'id': '54', 'type': 'argument_list', 'children': ['55', '57']},{'id': '55', 'type': 'list_splat', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'progArgs'},{'id': '57', 'type': 'dictionary_splat', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'progKwargs'},{'id': '59', 'type': 'as_pattern_target', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '61', 'type': 'block', 'children': ['62', '83', '176', '186', '207', '216', '272', '299', '305']},{'id': '62', 'type': 'if_statement', 'children': ['63', '64', '73']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'directed'},{'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': 'grph'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'DiGraph'},{'id': '72', 'type': 'argument_list', 'children': []},{'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': 'grph'},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'Graph'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'if_statement', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'nodeList'},{'id': '85', 'type': 'block', 'children': ['86', '96', '117', '126', '170']},{'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': 'PBar'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'updateVal'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93']},{'id': '92', 'type': 'integer', 'children': [], 'value': '0'},{'id': '93', 'type': 'binary_operator', 'children': ['94', '95'], 'value': '+'},{'id': '94', 'type': 'string', 'children': [], 'value': '"Reading "'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'nodeList'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '108']},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'expanduser'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '115']},{'id': '110', 'type': 'attribute', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'nodeList'},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'nFile'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'csv'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'DictReader'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '126', 'type': 'for_statement', 'children': ['127', '128', '129']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'nFile'},{'id': '129', 'type': 'block', 'children': ['130', '134', '140', '144']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'ndID'},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'idKey'},{'id': '140', 'type': 'delete_statement', 'children': ['141']},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'idKey'},{'id': '144', 'type': 'if_statement', 'children': ['145', '151', '161']},{'id': '145', 'type': 'comparison_operator', 'children': ['146', '150'], 'value': '>'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '150', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'grph'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'add_node'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'ndID'},{'id': '159', 'type': 'dictionary_splat', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '161', 'type': 'else_clause', 'children': ['162']},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'grph'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'add_node'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'ndID'},{'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': 'f'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '175', 'type': 'argument_list', 'children': []},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'updateVal'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183']},{'id': '182', 'type': 'float', 'children': [], 'value': '.25'},{'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '+'},{'id': '184', 'type': 'string', 'children': [], 'value': '"Reading "'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'edgeList'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '198']},{'id': '193', 'type': 'attribute', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'expanduser'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '205']},{'id': '200', 'type': 'attribute', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'abspath'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'edgeList'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'eFile'},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'csv'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'DictReader'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '216', 'type': 'for_statement', 'children': ['217', '218', '219']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'eFile'},{'id': '219', 'type': 'block', 'children': ['220', '224', '230', '236', '240', '244']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'eFrom'},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'eSource'},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'eTo'},{'id': '233', 'type': 'subscript', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'eDest'},{'id': '236', 'type': 'delete_statement', 'children': ['237']},{'id': '237', 'type': 'subscript', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'eSource'},{'id': '240', 'type': 'delete_statement', 'children': ['241']},{'id': '241', 'type': 'subscript', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'eDest'},{'id': '244', 'type': 'if_statement', 'children': ['245', '251', '262']},{'id': '245', 'type': 'comparison_operator', 'children': ['246', '250'], 'value': '>'},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '250', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'grph'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '257', 'type': 'argument_list', 'children': ['258', '259', '260']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'eFrom'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'eTo'},{'id': '260', 'type': 'dictionary_splat', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '262', 'type': 'else_clause', 'children': ['263']},{'id': '263', 'type': 'block', 'children': ['264']},{'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': 'grph'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '269', 'type': 'argument_list', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'eFrom'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'eTo'},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '277']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'finish'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'call', 'children': ['279', '282']},{'id': '279', 'type': 'attribute', 'children': ['280', '281']},{'id': '280', 'type': 'string', 'children': [], 'value': '"{} nodes and {} edges found"'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '282', 'type': 'argument_list', 'children': ['283', '291']},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '290']},{'id': '287', 'type': 'attribute', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'grph'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '290', 'type': 'argument_list', 'children': []},{'id': '291', 'type': 'call', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'grph'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '298', 'type': 'argument_list', 'children': []},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'call', 'children': ['301', '304']},{'id': '301', 'type': 'attribute', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '304', 'type': 'argument_list', 'children': []},{'id': '305', 'type': 'return_statement', 'children': ['306']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'grph'} | def readGraph(edgeList, nodeList = None, directed = False, idKey = 'ID', eSource = 'From', eDest = 'To'):
progArgs = (0, "Starting to reading graphs")
if metaknowledge.VERBOSE_MODE:
progKwargs = {'dummy' : False}
else:
progKwargs = {'dummy' : True}
with _ProgressBar(*progArgs, **progKwargs) as PBar:
if directed:
grph = nx.DiGraph()
else:
grph = nx.Graph()
if nodeList:
PBar.updateVal(0, "Reading " + nodeList)
f = open(os.path.expanduser(os.path.abspath(nodeList)))
nFile = csv.DictReader(f)
for line in nFile:
vals = line
ndID = vals[idKey]
del vals[idKey]
if len(vals) > 0:
grph.add_node(ndID, **vals)
else:
grph.add_node(ndID)
f.close()
PBar.updateVal(.25, "Reading " + edgeList)
f = open(os.path.expanduser(os.path.abspath(edgeList)))
eFile = csv.DictReader(f)
for line in eFile:
vals = line
eFrom = vals[eSource]
eTo = vals[eDest]
del vals[eSource]
del vals[eDest]
if len(vals) > 0:
grph.add_edge(eFrom, eTo, **vals)
else:
grph.add_edge(eFrom, eTo)
PBar.finish("{} nodes and {} edges found".format(len(grph.nodes()), len(grph.edges())))
f.close()
return grph |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'writeGraph'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'grph'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'edgeInfo'},{'id': '8', 'type': 'True', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'typing'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '14', 'type': 'string', 'children': [], 'value': "'csv'"},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '17', 'type': 'True', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'allSameAttribute'},{'id': '20', 'type': 'False', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '33', '54']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'progArgs'},{'id': '25', 'type': 'tuple', 'children': ['26', '27']},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'string', 'children': [], 'value': '"Writing the graph to files starting with: {}"'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '33', 'type': 'if_statement', 'children': ['34', '37', '45']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'metaknowledge'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_MODE'},{'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': 'progKwargs'},{'id': '41', 'type': 'dictionary', 'children': ['42']},{'id': '42', 'type': 'pair', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': "'dummy'"},{'id': '44', 'type': 'False', 'children': []},{'id': '45', 'type': 'else_clause', 'children': ['46']},{'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': 'progKwargs'},{'id': '50', 'type': 'dictionary', 'children': ['51']},{'id': '51', 'type': 'pair', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "'dummy'"},{'id': '53', 'type': 'True', 'children': []},{'id': '54', 'type': 'with_statement', 'children': ['55', '67']},{'id': '55', 'type': 'with_clause', 'children': ['56']},{'id': '56', 'type': 'with_item', 'children': ['57']},{'id': '57', 'type': 'as_pattern', 'children': ['58', '65']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_ProgressBar'},{'id': '60', 'type': 'argument_list', 'children': ['61', '63']},{'id': '61', 'type': 'list_splat', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'progArgs'},{'id': '63', 'type': 'dictionary_splat', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'progKwargs'},{'id': '65', 'type': 'as_pattern_target', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '67', 'type': 'block', 'children': ['68', '112', '137', '302', '340', '355', '367']},{'id': '68', 'type': 'if_statement', 'children': ['69', '70', '106']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'typing'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'if_statement', 'children': ['72', '95', '100']},{'id': '72', 'type': 'boolean_operator', 'children': ['73', '84'], 'value': 'or'},{'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': 'grph'},{'id': '77', 'type': 'attribute', 'children': ['78', '83']},{'id': '78', 'type': 'attribute', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'digraph'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'DiGraph'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'grph'},{'id': '88', 'type': 'attribute', 'children': ['89', '94']},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'multidigraph'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'MultiDiGraph'},{'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': 'grphType'},{'id': '99', 'type': 'string', 'children': [], 'value': '"_directed"'},{'id': '100', 'type': 'else_clause', 'children': ['101']},{'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': 'grphType'},{'id': '105', 'type': 'string', 'children': [], 'value': '"_undirected"'},{'id': '106', 'type': 'else_clause', 'children': ['107']},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'grphType'},{'id': '111', 'type': 'string', 'children': [], 'value': "''"},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'nameCompts'},{'id': '115', 'type': 'call', 'children': ['116', '121']},{'id': '116', 'type': 'attribute', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '128']},{'id': '123', 'type': 'attribute', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'expanduser'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'call', 'children': ['130', '135']},{'id': '130', 'type': 'attribute', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'normpath'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '137', 'type': 'if_statement', 'children': ['138', '149', '170', '205', '252']},{'id': '138', 'type': 'boolean_operator', 'children': ['139', '144'], 'value': 'and'},{'id': '139', 'type': 'comparison_operator', 'children': ['140', '143'], 'value': '=='},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'nameCompts'},{'id': '142', 'type': 'integer', 'children': [], 'value': '0'},{'id': '143', 'type': 'string', 'children': [], 'value': "''"},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '148'], 'value': '=='},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'nameCompts'},{'id': '147', 'type': 'integer', 'children': [], 'value': '1'},{'id': '148', 'type': 'string', 'children': [], 'value': "''"},{'id': '149', 'type': 'block', 'children': ['150', '160']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'edgeListName'},{'id': '153', 'type': 'binary_operator', 'children': ['154', '159'], 'value': '+'},{'id': '154', 'type': 'binary_operator', 'children': ['155', '158'], 'value': '+'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '+'},{'id': '156', 'type': 'string', 'children': [], 'value': '"edgeList"'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'grphType'},{'id': '158', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'nodesAtrName'},{'id': '163', 'type': 'binary_operator', 'children': ['164', '169'], 'value': '+'},{'id': '164', 'type': 'binary_operator', 'children': ['165', '168'], 'value': '+'},{'id': '165', 'type': 'binary_operator', 'children': ['166', '167'], 'value': '+'},{'id': '166', 'type': 'string', 'children': [], 'value': '"nodeAttributes"'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'grphType'},{'id': '168', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '170', 'type': 'elif_clause', 'children': ['171', '176']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '175'], 'value': '=='},{'id': '172', 'type': 'subscript', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'nameCompts'},{'id': '174', 'type': 'integer', 'children': [], 'value': '0'},{'id': '175', 'type': 'string', 'children': [], 'value': "''"},{'id': '176', 'type': 'block', 'children': ['177', '191']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'edgeListName'},{'id': '180', 'type': 'binary_operator', 'children': ['181', '190'], 'value': '+'},{'id': '181', 'type': 'binary_operator', 'children': ['182', '189'], 'value': '+'},{'id': '182', 'type': 'binary_operator', 'children': ['183', '188'], 'value': '+'},{'id': '183', 'type': 'binary_operator', 'children': ['184', '187'], 'value': '+'},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'nameCompts'},{'id': '186', 'type': 'integer', 'children': [], 'value': '1'},{'id': '187', 'type': 'string', 'children': [], 'value': '"_edgeList"'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'grphType'},{'id': '189', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'nodesAtrName'},{'id': '194', 'type': 'binary_operator', 'children': ['195', '204'], 'value': '+'},{'id': '195', 'type': 'binary_operator', 'children': ['196', '203'], 'value': '+'},{'id': '196', 'type': 'binary_operator', 'children': ['197', '202'], 'value': '+'},{'id': '197', 'type': 'binary_operator', 'children': ['198', '201'], 'value': '+'},{'id': '198', 'type': 'subscript', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'nameCompts'},{'id': '200', 'type': 'integer', 'children': [], 'value': '1'},{'id': '201', 'type': 'string', 'children': [], 'value': '"_nodeAttributes"'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'grphType'},{'id': '203', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '205', 'type': 'elif_clause', 'children': ['206', '211']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '210'], 'value': '=='},{'id': '207', 'type': 'subscript', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'nameCompts'},{'id': '209', 'type': 'integer', 'children': [], 'value': '1'},{'id': '210', 'type': 'string', 'children': [], 'value': "''"},{'id': '211', 'type': 'block', 'children': ['212', '232']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'edgeListName'},{'id': '215', 'type': 'call', 'children': ['216', '221']},{'id': '216', 'type': 'attribute', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '221', 'type': 'argument_list', 'children': ['222', '225']},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'nameCompts'},{'id': '224', 'type': 'integer', 'children': [], 'value': '0'},{'id': '225', 'type': 'binary_operator', 'children': ['226', '231'], 'value': '+'},{'id': '226', 'type': 'binary_operator', 'children': ['227', '230'], 'value': '+'},{'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '+'},{'id': '228', 'type': 'string', 'children': [], 'value': '"edgeList"'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'grphType'},{'id': '230', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'nodesAtrName'},{'id': '235', 'type': 'call', 'children': ['236', '241']},{'id': '236', 'type': 'attribute', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '241', 'type': 'argument_list', 'children': ['242', '245']},{'id': '242', 'type': 'subscript', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'nameCompts'},{'id': '244', 'type': 'integer', 'children': [], 'value': '0'},{'id': '245', 'type': 'binary_operator', 'children': ['246', '251'], 'value': '+'},{'id': '246', 'type': 'binary_operator', 'children': ['247', '250'], 'value': '+'},{'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '+'},{'id': '248', 'type': 'string', 'children': [], 'value': '"nodeAttributes"'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'grphType'},{'id': '250', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '252', 'type': 'else_clause', 'children': ['253']},{'id': '253', 'type': 'block', 'children': ['254', '278']},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'edgeListName'},{'id': '257', 'type': 'call', 'children': ['258', '263']},{'id': '258', 'type': 'attribute', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '263', 'type': 'argument_list', 'children': ['264', '267']},{'id': '264', 'type': 'subscript', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'nameCompts'},{'id': '266', 'type': 'integer', 'children': [], 'value': '0'},{'id': '267', 'type': 'binary_operator', 'children': ['268', '277'], 'value': '+'},{'id': '268', 'type': 'binary_operator', 'children': ['269', '276'], 'value': '+'},{'id': '269', 'type': 'binary_operator', 'children': ['270', '275'], 'value': '+'},{'id': '270', 'type': 'binary_operator', 'children': ['271', '274'], 'value': '+'},{'id': '271', 'type': 'subscript', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'nameCompts'},{'id': '273', 'type': 'integer', 'children': [], 'value': '1'},{'id': '274', 'type': 'string', 'children': [], 'value': '"_edgeList"'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'grphType'},{'id': '276', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'assignment', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'nodesAtrName'},{'id': '281', 'type': 'call', 'children': ['282', '287']},{'id': '282', 'type': 'attribute', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '287', 'type': 'argument_list', 'children': ['288', '291']},{'id': '288', 'type': 'subscript', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'nameCompts'},{'id': '290', 'type': 'integer', 'children': [], 'value': '0'},{'id': '291', 'type': 'binary_operator', 'children': ['292', '301'], 'value': '+'},{'id': '292', 'type': 'binary_operator', 'children': ['293', '300'], 'value': '+'},{'id': '293', 'type': 'binary_operator', 'children': ['294', '299'], 'value': '+'},{'id': '294', 'type': 'binary_operator', 'children': ['295', '298'], 'value': '+'},{'id': '295', 'type': 'subscript', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'nameCompts'},{'id': '297', 'type': 'integer', 'children': [], 'value': '1'},{'id': '298', 'type': 'string', 'children': [], 'value': '"_nodeAttributes"'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'grphType'},{'id': '300', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '302', 'type': 'if_statement', 'children': ['303', '305']},{'id': '303', 'type': 'not_operator', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'overwrite'},{'id': '305', 'type': 'block', 'children': ['306', '323']},{'id': '306', 'type': 'if_statement', 'children': ['307', '315']},{'id': '307', 'type': 'call', 'children': ['308', '313']},{'id': '308', 'type': 'attribute', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '313', 'type': 'argument_list', 'children': ['314']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'edgeListName'},{'id': '315', 'type': 'block', 'children': ['316']},{'id': '316', 'type': 'raise_statement', 'children': ['317']},{'id': '317', 'type': 'call', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '319', 'type': 'argument_list', 'children': ['320']},{'id': '320', 'type': 'binary_operator', 'children': ['321', '322'], 'value': '+'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'edgeListName'},{'id': '322', 'type': 'string', 'children': [], 'value': '" already exists"'},{'id': '323', 'type': 'if_statement', 'children': ['324', '332']},{'id': '324', 'type': 'call', 'children': ['325', '330']},{'id': '325', 'type': 'attribute', 'children': ['326', '329']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'isfile'},{'id': '330', 'type': 'argument_list', 'children': ['331']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'nodesAtrName'},{'id': '332', 'type': 'block', 'children': ['333']},{'id': '333', 'type': 'raise_statement', 'children': ['334']},{'id': '334', 'type': 'call', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'OSError'},{'id': '336', 'type': 'argument_list', 'children': ['337']},{'id': '337', 'type': 'binary_operator', 'children': ['338', '339'], 'value': '+'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'nodesAtrName'},{'id': '339', 'type': 'string', 'children': [], 'value': '" already exists"'},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'call', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'writeEdgeList'},{'id': '343', 'type': 'argument_list', 'children': ['344', '345', '346', '349', '352']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'grph'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'edgeListName'},{'id': '346', 'type': 'keyword_argument', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'extraInfo'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'edgeInfo'},{'id': '349', 'type': 'keyword_argument', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'allSameAttribute'},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'allSameAttribute'},{'id': '352', 'type': 'keyword_argument', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': '_progBar'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '355', 'type': 'expression_statement', 'children': ['356']},{'id': '356', 'type': 'call', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'writeNodeAttributeFile'},{'id': '358', 'type': 'argument_list', 'children': ['359', '360', '361', '364']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'grph'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'nodesAtrName'},{'id': '361', 'type': 'keyword_argument', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'allSameAttribute'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'allSameAttribute'},{'id': '364', 'type': 'keyword_argument', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': '_progBar'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '367', 'type': 'expression_statement', 'children': ['368']},{'id': '368', 'type': 'call', 'children': ['369', '372']},{'id': '369', 'type': 'attribute', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'finish'},{'id': '372', 'type': 'argument_list', 'children': ['373']},{'id': '373', 'type': 'call', 'children': ['374', '377']},{'id': '374', 'type': 'attribute', 'children': ['375', '376']},{'id': '375', 'type': 'string', 'children': [], 'value': '"{} nodes and {} edges written to file"'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '377', 'type': 'argument_list', 'children': ['378', '386']},{'id': '378', 'type': 'call', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '380', 'type': 'argument_list', 'children': ['381']},{'id': '381', 'type': 'call', 'children': ['382', '385']},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'grph'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '385', 'type': 'argument_list', 'children': []},{'id': '386', 'type': 'call', 'children': ['387', '388']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '388', 'type': 'argument_list', 'children': ['389']},{'id': '389', 'type': 'call', 'children': ['390', '393']},{'id': '390', 'type': 'attribute', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'grph'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '393', 'type': 'argument_list', 'children': []} | def writeGraph(grph, name, edgeInfo = True, typing = False, suffix = 'csv', overwrite = True, allSameAttribute = False):
progArgs = (0, "Writing the graph to files starting with: {}".format(name))
if metaknowledge.VERBOSE_MODE:
progKwargs = {'dummy' : False}
else:
progKwargs = {'dummy' : True}
with _ProgressBar(*progArgs, **progKwargs) as PBar:
if typing:
if isinstance(grph, nx.classes.digraph.DiGraph) or isinstance(grph, nx.classes.multidigraph.MultiDiGraph):
grphType = "_directed"
else:
grphType = "_undirected"
else:
grphType = ''
nameCompts = os.path.split(os.path.expanduser(os.path.normpath(name)))
if nameCompts[0] == '' and nameCompts[1] == '':
edgeListName = "edgeList"+ grphType + '.' + suffix
nodesAtrName = "nodeAttributes"+ grphType + '.' + suffix
elif nameCompts[0] == '':
edgeListName = nameCompts[1] + "_edgeList"+ grphType + '.' + suffix
nodesAtrName = nameCompts[1] + "_nodeAttributes"+ grphType + '.' + suffix
elif nameCompts[1] == '':
edgeListName = os.path.join(nameCompts[0], "edgeList"+ grphType + '.' + suffix)
nodesAtrName = os.path.join(nameCompts[0], "nodeAttributes"+ grphType + '.' + suffix)
else:
edgeListName = os.path.join(nameCompts[0], nameCompts[1] + "_edgeList"+ grphType + '.' + suffix)
nodesAtrName = os.path.join(nameCompts[0], nameCompts[1] + "_nodeAttributes"+ grphType + '.' + suffix)
if not overwrite:
if os.path.isfile(edgeListName):
raise OSError(edgeListName+ " already exists")
if os.path.isfile(nodesAtrName):
raise OSError(nodesAtrName + " already exists")
writeEdgeList(grph, edgeListName, extraInfo = edgeInfo, allSameAttribute = allSameAttribute, _progBar = PBar)
writeNodeAttributeFile(grph, nodesAtrName, allSameAttribute = allSameAttribute, _progBar = PBar)
PBar.finish("{} nodes and {} edges written to file".format(len(grph.nodes()), len(grph.edges()))) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'mergeGraphs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'targetGraph'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'addedGraph'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'incrementedNodeVal'},{'id': '8', 'type': 'string', 'children': [], 'value': "'count'"},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'incrementedEdgeVal'},{'id': '11', 'type': 'string', 'children': [], 'value': "'weight'"},{'id': '12', 'type': 'block', 'children': ['13', '75']},{'id': '13', 'type': 'for_statement', 'children': ['14', '17', '25']},{'id': '14', 'type': 'pattern_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'addedNode'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'addedGraph'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '24', 'type': 'True', 'children': []},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '28', '55']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'incrementedNodeVal'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'try_statement', 'children': ['30', '43']},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'augmented_assignment', 'children': ['33', '40'], 'value': '+='},{'id': '33', 'type': 'subscript', 'children': ['34', '39']},{'id': '34', 'type': 'subscript', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'targetGraph'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'addedNode'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'incrementedNodeVal'},{'id': '40', 'type': 'subscript', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'incrementedNodeVal'},{'id': '43', 'type': 'except_clause', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'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': 'targetGraph'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'add_node'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'addedNode'},{'id': '53', 'type': 'dictionary_splat', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '55', 'type': 'else_clause', 'children': ['56']},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'if_statement', 'children': ['58', '65']},{'id': '58', 'type': 'not_operator', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'targetGraph'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'has_node'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'addedNode'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'targetGraph'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'add_node'},{'id': '71', 'type': 'argument_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'addedNode'},{'id': '73', 'type': 'dictionary_splat', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '75', 'type': 'for_statement', 'children': ['76', '80', '88']},{'id': '76', 'type': 'pattern_list', 'children': ['77', '78', '79']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'edgeNode1'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'edgeNode2'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'addedGraph'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '87', 'type': 'True', 'children': []},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'if_statement', 'children': ['90', '91', '120']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'incrementedEdgeVal'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'try_statement', 'children': ['93', '107']},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'augmented_assignment', 'children': ['96', '104'], 'value': '+='},{'id': '96', 'type': 'subscript', 'children': ['97', '103']},{'id': '97', 'type': 'subscript', 'children': ['98', '101', '102']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'targetGraph'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'edgeNode1'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'edgeNode2'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'incrementedEdgeVal'},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'incrementedEdgeVal'},{'id': '107', 'type': 'except_clause', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'targetGraph'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '115', 'type': 'argument_list', 'children': ['116', '117', '118']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'edgeNode1'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'edgeNode2'},{'id': '118', 'type': 'dictionary_splat', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'attribs'},{'id': '120', 'type': 'else_clause', 'children': ['121']},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'if_statement', 'children': ['123', '133']},{'id': '123', 'type': 'not_operator', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '130']},{'id': '125', 'type': 'attribute', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'targetGraph'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'Graph'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'has_edge'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'edgeNode1'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'edgeNode2'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'targetGraph'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141', '142']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'edgeNode1'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'edgeNode2'},{'id': '142', 'type': 'dictionary_splat', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'attribs'} | def mergeGraphs(targetGraph, addedGraph, incrementedNodeVal = 'count', incrementedEdgeVal = 'weight'):
for addedNode, attribs in addedGraph.nodes(data = True):
if incrementedNodeVal:
try:
targetGraph.node[addedNode][incrementedNodeVal] += attribs[incrementedNodeVal]
except KeyError:
targetGraph.add_node(addedNode, **attribs)
else:
if not targetGraph.has_node(addedNode):
targetGraph.add_node(addedNode, **attribs)
for edgeNode1, edgeNode2, attribs in addedGraph.edges(data = True):
if incrementedEdgeVal:
try:
targetGraph.edges[edgeNode1, edgeNode2][incrementedEdgeVal] += attribs[incrementedEdgeVal]
except KeyError:
targetGraph.add_edge(edgeNode1, edgeNode2, **attribs)
else:
if not targetGraph.Graph.has_edge(edgeNode1, edgeNode2):
targetGraph.add_edge(edgeNode1, edgeNode2, **attribs) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'writeRecord'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'if_statement', 'children': ['8', '11', '27']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'bad'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'raise_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'BadPubmedRecord'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': '"This record cannot be converted to a file as the input was malformed.\\nThe original line number (if any) is: {} and the original file is: \'{}\'"'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '20', 'type': 'argument_list', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_sourceLine'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_sourceFile'},{'id': '27', 'type': 'else_clause', 'children': ['28']},{'id': '28', 'type': 'block', 'children': ['29', '33', '143']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'authTags'},{'id': '32', 'type': 'dictionary', 'children': []},{'id': '33', 'type': 'for_statement', 'children': ['34', '35', '36']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'authorBasedTags'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'for_statement', 'children': ['38', '39', '48']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'val'},{'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': '_fieldDict'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '47', 'type': 'list', 'children': [], 'value': '[]'},{'id': '48', 'type': 'block', 'children': ['49', '58']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': "' : '"},{'id': '58', 'type': 'try_statement', 'children': ['59', '101']},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '69']},{'id': '62', 'type': 'attribute', 'children': ['63', '68']},{'id': '63', 'type': 'subscript', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'authTags'},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': '"{0}{1}- {2}\\n"'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76', '85']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '76', 'type': 'binary_operator', 'children': ['77', '78'], 'value': '*'},{'id': '77', 'type': 'string', 'children': [], 'value': "' '"},{'id': '78', 'type': '()', 'children': ['79']},{'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '-'},{'id': '80', 'type': 'integer', 'children': [], 'value': '4'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '85', 'type': 'call', 'children': ['86', '98']},{'id': '86', 'type': 'attribute', 'children': ['87', '97']},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'string', 'children': [], 'value': "' : '"},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '94', 'type': 'slice', 'children': ['95', '96']},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'},{'id': '96', 'type': 'colon', 'children': []},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '98', 'type': 'argument_list', 'children': ['99', '100']},{'id': '99', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '100', 'type': 'string', 'children': [], 'value': "'\\n '"},{'id': '101', 'type': 'except_clause', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '111']},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'authTags'},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'list', 'children': ['112'], 'value': '["{0}{1}- {2}\\n".format(tag, \' \' * (4 - len(tag)),\' : \'.join(split[1:]).replace(\'\\n\', \'\\n \'))]'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'string', 'children': [], 'value': '"{0}{1}- {2}\\n"'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118', '127']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '*'},{'id': '119', 'type': 'string', 'children': [], 'value': "' '"},{'id': '120', 'type': '()', 'children': ['121']},{'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '-'},{'id': '122', 'type': 'integer', 'children': [], 'value': '4'},{'id': '123', 'type': 'call', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '125', 'type': 'argument_list', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '127', 'type': 'call', 'children': ['128', '140']},{'id': '128', 'type': 'attribute', 'children': ['129', '139']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': "' : '"},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '136', 'type': 'slice', 'children': ['137', '138']},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'colon', 'children': []},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '140', 'type': 'argument_list', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '142', 'type': 'string', 'children': [], 'value': "'\\n '"},{'id': '143', 'type': 'for_statement', 'children': ['144', '147', '154']},{'id': '144', 'type': 'pattern_list', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '147', 'type': 'call', 'children': ['148', '153']},{'id': '148', 'type': 'attribute', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_fieldDict'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '153', 'type': 'argument_list', 'children': []},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'if_statement', 'children': ['156', '159', '161']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'in'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'authorBasedTags'},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'continue_statement', 'children': []},{'id': '161', 'type': 'else_clause', 'children': ['162']},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'for_statement', 'children': ['164', '165', '166']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '166', 'type': 'block', 'children': ['167', '195']},{'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': 'f'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'write'},{'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': '"{0}{1}- {2}\\n"'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179', '188']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '*'},{'id': '180', 'type': 'string', 'children': [], 'value': "' '"},{'id': '181', 'type': '()', 'children': ['182']},{'id': '182', 'type': 'binary_operator', 'children': ['183', '184'], 'value': '-'},{'id': '183', 'type': 'integer', 'children': [], 'value': '4'},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '188', 'type': 'call', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '192', 'type': 'argument_list', 'children': ['193', '194']},{'id': '193', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '194', 'type': 'string', 'children': [], 'value': "'\\n '"},{'id': '195', 'type': 'if_statement', 'children': ['196', '199']},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '198'], 'value': '=='},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '198', 'type': 'string', 'children': [], 'value': "'AU'"},{'id': '199', 'type': 'block', 'children': ['200']},{'id': '200', 'type': 'for_statement', 'children': ['201', '202', '209']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'authVal'},{'id': '202', 'type': 'call', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'authTags'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '208', 'type': 'list', 'children': [], 'value': '[]'},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'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': 'write'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'authVal'} | def writeRecord(self, f):
if self.bad:
raise BadPubmedRecord("This record cannot be converted to a file as the input was malformed.\nThe original line number (if any) is: {} and the original file is: '{}'".format(self._sourceLine, self._sourceFile))
else:
authTags = {}
for tag in authorBasedTags:
for val in self._fieldDict.get(tag, []):
split = val.split(' : ')
try:
authTags[split[0]].append("{0}{1}- {2}\n".format(tag, ' ' * (4 - len(tag)),' : '.join(split[1:]).replace('\n', '\n ')))
except KeyError:
authTags[split[0]] = ["{0}{1}- {2}\n".format(tag, ' ' * (4 - len(tag)),' : '.join(split[1:]).replace('\n', '\n '))]
for tag, value in self._fieldDict.items():
if tag in authorBasedTags:
continue
else:
for v in value:
f.write("{0}{1}- {2}\n".format(tag, ' ' * (4 - len(tag)), v.replace('\n', '\n ')))
if tag == 'AU':
for authVal in authTags.get(v,[]):
f.write(authVal) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'graphDensityContourPlot'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'iters'},{'id': '7', 'type': 'integer', 'children': [], 'value': '50'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'layoutScaleFactor'},{'id': '13', 'type': 'integer', 'children': [], 'value': '1'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'overlay'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'nodeSize'},{'id': '19', 'type': 'integer', 'children': [], 'value': '10'},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'axisSamples'},{'id': '22', 'type': 'integer', 'children': [], 'value': '100'},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'blurringFactor'},{'id': '25', 'type': 'float', 'children': [], 'value': '.1'},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'contours'},{'id': '28', 'type': 'integer', 'children': [], 'value': '15'},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'graphType'},{'id': '31', 'type': 'string', 'children': [], 'value': "'coloured'"},{'id': '32', 'type': 'block', 'children': ['33', '39', '79', '258', '266', '277', '302', '318', '331', '343', '373', '380', '387']},{'id': '33', 'type': 'import_from_statement', 'children': ['34', '37']},{'id': '34', 'type': 'dotted_name', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'mpl_toolkits'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'mplot3d'},{'id': '37', 'type': 'dotted_name', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'Axes3D'},{'id': '39', 'type': 'if_statement', 'children': ['40', '65']},{'id': '40', 'type': 'boolean_operator', 'children': ['41', '53'], 'value': 'and'},{'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': 'G'},{'id': '46', 'type': 'attribute', 'children': ['47', '52']},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'digraph'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'DiGraph'},{'id': '53', 'type': 'not_operator', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '58', 'type': 'attribute', 'children': ['59', '64']},{'id': '59', 'type': 'attribute', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'Graph'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'raise_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': '"{} is not a valid input."'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '79', 'type': 'if_statement', 'children': ['80', '83', '153', '243']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'is'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '82', 'type': 'None', 'children': []},{'id': '83', 'type': 'block', 'children': ['84', '101', '117']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'spring_layout'},{'id': '91', 'type': 'argument_list', 'children': ['92', '93', '98']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'scale'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '-'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'axisSamples'},{'id': '97', 'type': 'integer', 'children': [], 'value': '1'},{'id': '98', 'type': 'keyword_argument', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'iterations'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'iters'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '108', 'type': 'argument_list', 'children': ['109', '112']},{'id': '109', 'type': 'list', 'children': ['110', '111'], 'value': '[axisSamples, axisSamples]'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'axisSamples'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'axisSamples'},{'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'float32'},{'id': '117', 'type': 'for_statement', 'children': ['118', '119', '124']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'block', 'children': ['125', '145']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '130']},{'id': '127', 'type': 'pattern_list', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '132', 'type': 'generator_expression', 'children': ['133', '137']},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '137', 'type': 'for_in_clause', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'integer', 'children': [], 'value': '0'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'augmented_assignment', 'children': ['147', '152'], 'value': '+='},{'id': '147', 'type': 'subscript', 'children': ['148', '151']},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '152', 'type': 'integer', 'children': [], 'value': '1'},{'id': '153', 'type': 'elif_clause', 'children': ['154', '159']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '159', 'type': 'block', 'children': ['160', '168', '184', '193']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '167', 'type': 'argument_list', 'children': []},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '175', 'type': 'argument_list', 'children': ['176', '179']},{'id': '176', 'type': 'list', 'children': ['177', '178'], 'value': '[axisSamples, axisSamples]'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'axisSamples'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'axisSamples'},{'id': '179', 'type': 'keyword_argument', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'float32'},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'multFactor'},{'id': '187', 'type': 'binary_operator', 'children': ['188', '192'], 'value': '/'},{'id': '188', 'type': '()', 'children': ['189']},{'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '-'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'axisSamples'},{'id': '191', 'type': 'integer', 'children': [], 'value': '1'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'layoutScaleFactor'},{'id': '193', 'type': 'for_statement', 'children': ['194', '195', '200']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '199', 'type': 'argument_list', 'children': []},{'id': '200', 'type': 'block', 'children': ['201', '209', '215', '235']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'assignment', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'tmpPos'},{'id': '204', 'type': 'binary_operator', 'children': ['205', '208'], 'value': '*'},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'multFactor'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '214']},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'tmpPos'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '220']},{'id': '217', 'type': 'pattern_list', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '222', 'type': 'generator_expression', 'children': ['223', '227']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '227', 'type': 'for_in_clause', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'tmpPos'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'integer', 'children': [], 'value': '0'},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'augmented_assignment', 'children': ['237', '242'], 'value': '+='},{'id': '237', 'type': 'subscript', 'children': ['238', '241']},{'id': '238', 'type': 'subscript', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '242', 'type': 'integer', 'children': [], 'value': '1'},{'id': '243', 'type': 'else_clause', 'children': ['244']},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'raise_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '248', 'type': 'argument_list', 'children': ['249']},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'string', 'children': [], 'value': '"{} is not a valid input."'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '256', 'type': 'argument_list', 'children': ['257']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'fig'},{'id': '261', 'type': 'call', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'figure'},{'id': '265', 'type': 'argument_list', 'children': []},{'id': '266', 'type': 'expression_statement', 'children': ['267']},{'id': '267', 'type': 'assignment', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'fig'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'gca'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'projection'},{'id': '276', 'type': 'string', 'children': [], 'value': "'3d'"},{'id': '277', 'type': 'if_statement', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'overlay'},{'id': '279', 'type': 'block', 'children': ['280']},{'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': 'nx'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'draw_networkx'},{'id': '285', 'type': 'argument_list', 'children': ['286', '287', '290', '293', '296', '299']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '287', 'type': 'keyword_argument', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'layout'},{'id': '290', 'type': 'keyword_argument', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'ax'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '293', 'type': 'keyword_argument', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'node_size'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'nodeSize'},{'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'with_labels'},{'id': '298', 'type': 'False', 'children': []},{'id': '299', 'type': 'keyword_argument', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'edgelist'},{'id': '301', 'type': 'list', 'children': [], 'value': '[]'},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'assignment', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'ndi'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'gaussian_filter'},{'id': '309', 'type': 'argument_list', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '311', 'type': 'tuple', 'children': ['312', '315']},{'id': '312', 'type': 'binary_operator', 'children': ['313', '314'], 'value': '*'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'blurringFactor'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'axisSamples'},{'id': '315', 'type': 'binary_operator', 'children': ['316', '317'], 'value': '*'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'blurringFactor'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'axisSamples'},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'assignment', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '321', 'type': 'assignment', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'Y'},{'id': '323', 'type': 'call', 'children': ['324', '327']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '327', 'type': 'argument_list', 'children': ['328', '329', '330']},{'id': '328', 'type': 'integer', 'children': [], 'value': '0'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'axisSamples'},{'id': '330', 'type': 'integer', 'children': [], 'value': '1'},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'assignment', 'children': ['333', '336']},{'id': '333', 'type': 'pattern_list', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'Y'},{'id': '336', 'type': 'call', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'meshgrid'},{'id': '340', 'type': 'argument_list', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'Y'},{'id': '343', 'type': 'if_statement', 'children': ['344', '347', '359']},{'id': '344', 'type': 'comparison_operator', 'children': ['345', '346'], 'value': '=='},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'graphType'},{'id': '346', 'type': 'string', 'children': [], 'value': '"solid"'},{'id': '347', 'type': 'block', 'children': ['348']},{'id': '348', 'type': 'expression_statement', 'children': ['349']},{'id': '349', 'type': 'assignment', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'CS'},{'id': '351', 'type': 'call', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'plot_surface'},{'id': '355', 'type': 'argument_list', 'children': ['356', '357', '358']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'Y'},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '359', 'type': 'else_clause', 'children': ['360']},{'id': '360', 'type': 'block', 'children': ['361']},{'id': '361', 'type': 'expression_statement', 'children': ['362']},{'id': '362', 'type': 'assignment', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'CS'},{'id': '364', 'type': 'call', 'children': ['365', '368']},{'id': '365', 'type': 'attribute', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'contourf'},{'id': '368', 'type': 'argument_list', 'children': ['369', '370', '371', '372']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'Y'},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'grid'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'contours'},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'call', 'children': ['375', '378']},{'id': '375', 'type': 'attribute', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'},{'id': '378', 'type': 'argument_list', 'children': ['379']},{'id': '379', 'type': 'string', 'children': [], 'value': "'X'"},{'id': '380', 'type': 'expression_statement', 'children': ['381']},{'id': '381', 'type': 'call', 'children': ['382', '385']},{'id': '382', 'type': 'attribute', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '384', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'},{'id': '385', 'type': 'argument_list', 'children': ['386']},{'id': '386', 'type': 'string', 'children': [], 'value': "'Y'"},{'id': '387', 'type': 'expression_statement', 'children': ['388']},{'id': '388', 'type': 'call', 'children': ['389', '392']},{'id': '389', 'type': 'attribute', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'set_zlabel'},{'id': '392', 'type': 'argument_list', 'children': ['393']},{'id': '393', 'type': 'string', 'children': [], 'value': "'Node Density'"} | def graphDensityContourPlot(G, iters = 50, layout = None, layoutScaleFactor = 1, overlay = False, nodeSize = 10, axisSamples = 100, blurringFactor = .1, contours = 15, graphType = 'coloured'):
from mpl_toolkits.mplot3d import Axes3D
if not isinstance(G, nx.classes.digraph.DiGraph) and not isinstance(G, nx.classes.graph.Graph):
raise TypeError("{} is not a valid input.".format(type(G)))
if layout is None:
layout = nx.spring_layout(G, scale = axisSamples - 1, iterations = iters)
grid = np.zeros( [axisSamples, axisSamples],dtype=np.float32)
for v in layout.values():
x, y = tuple(int(x) for x in v.round(0))
grid[y][x] += 1
elif isinstance(layout, dict):
layout = layout.copy()
grid = np.zeros([axisSamples, axisSamples],dtype=np.float32)
multFactor = (axisSamples - 1) / layoutScaleFactor
for k in layout.keys():
tmpPos = layout[k] * multFactor
layout[k] = tmpPos
x, y = tuple(int(x) for x in tmpPos.round(0))
grid[y][x] += 1
else:
raise TypeError("{} is not a valid input.".format(type(layout)))
fig = plt.figure()
axis = fig.gca(projection='3d')
if overlay:
nx.draw_networkx(G, pos = layout, ax = axis, node_size = nodeSize, with_labels = False, edgelist = [])
grid = ndi.gaussian_filter(grid, (blurringFactor * axisSamples, blurringFactor * axisSamples))
X = Y = np.arange(0, axisSamples, 1)
X, Y = np.meshgrid(X, Y)
if graphType == "solid":
CS = axis.plot_surface(X,Y, grid)
else:
CS = axis.contourf(X, Y, grid, contours)
axis.set_xlabel('X')
axis.set_ylabel('Y')
axis.set_zlabel('Node Density') |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'makeNodeTuple'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'citation'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'idVal'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'nodeInfo'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'fullInfo'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'coreCitesDict'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'coreValues'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'detailedValues'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'addCR'},{'id': '14', 'type': 'block', 'children': ['15', '19', '304', '316', '325']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '18', 'type': 'dictionary', 'children': []},{'id': '19', 'type': 'if_statement', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'nodeInfo'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'if_statement', 'children': ['23', '26', '249', '282', '296']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': '=='},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '25', 'type': 'string', 'children': [], 'value': "'full'"},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'if_statement', 'children': ['28', '29', '237']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'coreValues'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'if_statement', 'children': ['31', '34', '204']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': 'in'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'citation'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'coreCitesDict'},{'id': '34', 'type': 'block', 'children': ['35', '41', '49', '171', '177']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'coreCitesDict'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'citation'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '46']},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '45', 'type': 'string', 'children': [], 'value': "'MK-ID'"},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '49', 'type': 'if_statement', 'children': ['50', '52', '126']},{'id': '50', 'type': 'not_operator', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'detailedValues'},{'id': '52', 'type': 'block', 'children': ['53', '57', '115']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'infoVals'},{'id': '56', 'type': 'list', 'children': [], 'value': '[]'},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'coreValues'},{'id': '60', 'type': 'block', 'children': ['61', '70']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'tagVal'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '70', 'type': 'if_statement', 'children': ['71', '76', '90', '112']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '73', 'type': 'argument_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'tagVal'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'infoVals'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'tagVal'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "','"},{'id': '89', 'type': 'string', 'children': [], 'value': "''"},{'id': '90', 'type': 'elif_clause', 'children': ['91', '96']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'tagVal'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'infoVals'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '109']},{'id': '104', 'type': 'attribute', 'children': ['105', '108']},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'tagVal'},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': "','"},{'id': '111', 'type': 'string', 'children': [], 'value': "''"},{'id': '112', 'type': 'else_clause', 'children': ['113']},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'pass_statement', 'children': []},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '120']},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '119', 'type': 'string', 'children': [], 'value': "'info'"},{'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': 'identifier', 'children': [], 'value': 'infoVals'},{'id': '126', 'type': 'else_clause', 'children': ['127']},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'for_statement', 'children': ['129', '130', '131']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'coreValues'},{'id': '131', 'type': 'block', 'children': ['132', '142']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '141', 'type': 'None', 'children': []},{'id': '142', 'type': 'if_statement', 'children': ['143', '148', '163']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '148', 'type': 'block', 'children': ['149']},{'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': 'd'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'string', 'children': [], 'value': "'|'"},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '163', 'type': 'else_clause', 'children': ['164']},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'assignment', 'children': ['167', '170']},{'id': '167', 'type': 'subscript', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'v'},{'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': 'd'},{'id': '175', 'type': 'string', 'children': [], 'value': "'inCore'"},{'id': '176', 'type': 'True', 'children': []},{'id': '177', 'type': 'if_statement', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'addCR'},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '185']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '184', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'string', 'children': [], 'value': "'|'"},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'generator_expression', 'children': ['191', '195']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '195', 'type': 'for_in_clause', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '201', 'type': 'argument_list', 'children': ['202', '203']},{'id': '202', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '203', 'type': 'list', 'children': [], 'value': '[]'},{'id': '204', 'type': 'else_clause', 'children': ['205']},{'id': '205', 'type': 'block', 'children': ['206', '212', '222', '228']},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '211']},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '210', 'type': 'string', 'children': [], 'value': "'MK-ID'"},{'id': '211', 'type': 'string', 'children': [], 'value': "'None'"},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '217']},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '216', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'citation'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'allButDOI'},{'id': '221', 'type': 'argument_list', 'children': []},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '227']},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '226', 'type': 'string', 'children': [], 'value': "'inCore'"},{'id': '227', 'type': 'False', 'children': []},{'id': '228', 'type': 'if_statement', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'addCR'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '236']},{'id': '233', 'type': 'subscript', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '235', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '236', 'type': 'string', 'children': [], 'value': "''"},{'id': '237', 'type': 'else_clause', 'children': ['238']},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '244']},{'id': '241', 'type': 'subscript', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '243', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'citation'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'allButDOI'},{'id': '248', 'type': 'argument_list', 'children': []},{'id': '249', 'type': 'elif_clause', 'children': ['250', '253']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': '=='},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '252', 'type': 'string', 'children': [], 'value': "'journal'"},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'if_statement', 'children': ['255', '260', '274']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'citation'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'isJournal'},{'id': '259', 'type': 'argument_list', 'children': []},{'id': '260', 'type': 'block', 'children': ['261']},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '266']},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '265', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '266', 'type': 'call', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '268', 'type': 'argument_list', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'citation'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'FullJournalName'},{'id': '273', 'type': 'argument_list', 'children': []},{'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', '281']},{'id': '278', 'type': 'subscript', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '280', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '281', 'type': 'string', 'children': [], 'value': '"None"'},{'id': '282', 'type': 'elif_clause', 'children': ['283', '286']},{'id': '283', 'type': 'comparison_operator', 'children': ['284', '285'], 'value': '=='},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '285', 'type': 'string', 'children': [], 'value': "'original'"},{'id': '286', 'type': 'block', 'children': ['287']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '292']},{'id': '289', 'type': 'subscript', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '291', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '292', 'type': 'call', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'citation'},{'id': '296', 'type': 'else_clause', 'children': ['297']},{'id': '297', 'type': 'block', 'children': ['298']},{'id': '298', 'type': 'expression_statement', 'children': ['299']},{'id': '299', 'type': 'assignment', 'children': ['300', '303']},{'id': '300', 'type': 'subscript', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '302', 'type': 'string', 'children': [], 'value': "'info'"},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'idVal'},{'id': '304', 'type': 'if_statement', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'fullInfo'},{'id': '306', 'type': 'block', 'children': ['307']},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'assignment', 'children': ['309', '312']},{'id': '309', 'type': 'subscript', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '311', 'type': 'string', 'children': [], 'value': "'fullCite'"},{'id': '312', 'type': 'call', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '314', 'type': 'argument_list', 'children': ['315']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'citation'},{'id': '316', 'type': 'if_statement', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '318', 'type': 'block', 'children': ['319']},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'assignment', 'children': ['321', '324']},{'id': '321', 'type': 'subscript', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '323', 'type': 'string', 'children': [], 'value': "'count'"},{'id': '324', 'type': 'integer', 'children': [], 'value': '1'},{'id': '325', 'type': 'return_statement', 'children': ['326']},{'id': '326', 'type': 'tuple', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'idVal'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'd'} | def makeNodeTuple(citation, idVal, nodeInfo, fullInfo, nodeType, count, coreCitesDict, coreValues, detailedValues, addCR):
d = {}
if nodeInfo:
if nodeType == 'full':
if coreValues:
if citation in coreCitesDict:
R = coreCitesDict[citation]
d['MK-ID'] = R.id
if not detailedValues:
infoVals = []
for tag in coreValues:
tagVal = R.get(tag)
if isinstance(tagVal, str):
infoVals.append(tagVal.replace(',',''))
elif isinstance(tagVal, list):
infoVals.append(tagVal[0].replace(',',''))
else:
pass
d['info'] = ', '.join(infoVals)
else:
for tag in coreValues:
v = R.get(tag, None)
if isinstance(v, list):
d[tag] = '|'.join(sorted(v))
else:
d[tag] = v
d['inCore'] = True
if addCR:
d['citations'] = '|'.join((str(c) for c in R.get('citations', [])))
else:
d['MK-ID'] = 'None'
d['info'] = citation.allButDOI()
d['inCore'] = False
if addCR:
d['citations'] = ''
else:
d['info'] = citation.allButDOI()
elif nodeType == 'journal':
if citation.isJournal():
d['info'] = str(citation.FullJournalName())
else:
d['info'] = "None"
elif nodeType == 'original':
d['info'] = str(citation)
else:
d['info'] = idVal
if fullInfo:
d['fullCite'] = str(citation)
if count:
d['count'] = 1
return (idVal, d) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'expandRecs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'RecCollect'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'weighted'},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'for_statement', 'children': ['10', '11', '12']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'Rec'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'RecCollect'},{'id': '12', 'type': 'block', 'children': ['13', '32']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fullCiteList'},{'id': '16', 'type': 'list_comprehension', 'children': ['17', '22']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'makeID'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'Rec'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'createCitation'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'keyword_argument', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'multiCite'},{'id': '31', 'type': 'True', 'children': []},{'id': '32', 'type': 'if_statement', 'children': ['33', '39']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '38'], 'value': '>'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'fullCiteList'},{'id': '38', 'type': 'integer', 'children': [], 'value': '1'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'for_statement', 'children': ['41', '44', '48']},{'id': '41', 'type': 'pattern_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'citeID1'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'fullCiteList'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'if_statement', 'children': ['50', '53']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'in'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'citeID1'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'for_statement', 'children': ['55', '56', '63']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'citeID2'},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'fullCiteList'},{'id': '58', 'type': 'slice', 'children': ['59', '62']},{'id': '59', 'type': 'binary_operator', 'children': ['60', '61'], 'value': '+'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '61', 'type': 'integer', 'children': [], 'value': '1'},{'id': '62', 'type': 'colon', 'children': []},{'id': '63', 'type': 'block', 'children': ['64', '136']},{'id': '64', 'type': 'if_statement', 'children': ['65', '68', '106']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'not'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'citeID2'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '68', 'type': 'block', 'children': ['69', '82']},{'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': 'G'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'add_node'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'citeID2'},{'id': '76', 'type': 'dictionary_splat', 'children': ['77']},{'id': '77', 'type': 'subscript', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'citeID1'},{'id': '82', 'type': 'if_statement', 'children': ['83', '84', '96']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'weighted'},{'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': 'G'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92', '93']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'citeID1'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'citeID2'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '95', 'type': 'integer', 'children': [], 'value': '1'},{'id': '96', 'type': 'else_clause', 'children': ['97']},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '103', 'type': 'argument_list', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'citeID1'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'citeID2'},{'id': '106', 'type': 'elif_clause', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'weighted'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'try_statement', 'children': ['110', '122']},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'augmented_assignment', 'children': ['113', '121'], 'value': '+='},{'id': '113', 'type': 'subscript', 'children': ['114', '120']},{'id': '114', 'type': 'subscript', 'children': ['115', '118', '119']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'citeID1'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'citeID2'},{'id': '120', 'type': 'string', 'children': [], 'value': "'weight'"},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'except_clause', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132', '133']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'citeID1'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'citeID2'},{'id': '133', 'type': 'keyword_argument', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '135', 'type': 'integer', 'children': [], 'value': '1'},{'id': '136', 'type': 'for_statement', 'children': ['137', '141', '150']},{'id': '137', 'type': 'pattern_list', 'children': ['138', '139', '140']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'e1'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'citeID1'},{'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '149', 'type': 'True', 'children': []},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'G'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158', '159']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'citeID2'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'e2'},{'id': '159', 'type': 'dictionary_splat', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'data'} | def expandRecs(G, RecCollect, nodeType, weighted):
for Rec in RecCollect:
fullCiteList = [makeID(c, nodeType) for c in Rec.createCitation(multiCite = True)]
if len(fullCiteList) > 1:
for i, citeID1 in enumerate(fullCiteList):
if citeID1 in G:
for citeID2 in fullCiteList[i + 1:]:
if citeID2 not in G:
G.add_node(citeID2, **G.node[citeID1])
if weighted:
G.add_edge(citeID1, citeID2, weight = 1)
else:
G.add_edge(citeID1, citeID2)
elif weighted:
try:
G.edges[citeID1, citeID2]['weight'] += 1
except KeyError:
G.add_edge(citeID1, citeID2, weight = 1)
for e1, e2, data in G.edges(citeID1, data = True):
G.add_edge(citeID2, e2, **data) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'writeBib'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'maxStringLength'},{'id': '10', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'wosMode'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'reducedOutput'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'niceIDs'},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '60', '67', '123']},{'id': '21', 'type': 'if_statement', 'children': ['22', '23', '37']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31', '34']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '33', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '34', 'type': 'keyword_argument', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '36', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '37', 'type': 'else_clause', 'children': ['38']},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '44', 'type': 'argument_list', 'children': ['45', '54', '57']},{'id': '45', 'type': 'binary_operator', 'children': ['46', '53'], 'value': '+'},{'id': '46', 'type': 'subscript', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '50', 'type': 'slice', 'children': ['51', '52']},{'id': '51', 'type': 'colon', 'children': []},{'id': '52', 'type': 'integer', 'children': [], 'value': '200'},{'id': '53', 'type': 'string', 'children': [], 'value': "'.bib'"},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '56', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '59', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'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': 'f'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'string', 'children': [], 'value': '"%This file was generated by the metaknowledge Python package.\\n%The contents have been automatically generated and are likely to not work with\\n%LaTeX without some human intervention. This file is meant for other automatic\\n%systems and not to be used directly for making citations\\n"'},{'id': '67', 'type': 'for_statement', 'children': ['68', '69', '70']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'try_statement', 'children': ['72', '103', '107']},{'id': '72', 'type': 'block', 'children': ['73', '80']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'string', 'children': [], 'value': "'\\n\\n'"},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'bibString'},{'id': '90', 'type': 'argument_list', 'children': ['91', '94', '97', '100']},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'maxLength'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'maxStringLength'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'WOSMode'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'wosMode'},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'restrictedOutput'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'reducedOutput'},{'id': '100', 'type': 'keyword_argument', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'niceID'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'niceIDs'},{'id': '103', 'type': 'except_clause', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'BadWOSRecord'},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'pass_statement', 'children': []},{'id': '107', 'type': 'except_clause', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'raise_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'RecordsNotCompatible'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'string', 'children': [], 'value': '"The Record \'{}\', with ID \'{}\' does not support writing to bibtext files."'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '128', 'type': 'argument_list', 'children': []} | def writeBib(self, fname = None, maxStringLength = 1000, wosMode = False, reducedOutput = False, niceIDs = True):
if fname:
f = open(fname, mode = 'w', encoding = 'utf-8')
else:
f = open(self.name[:200] + '.bib', mode = 'w', encoding = 'utf-8')
f.write("%This file was generated by the metaknowledge Python package.\n%The contents have been automatically generated and are likely to not work with\n%LaTeX without some human intervention. This file is meant for other automatic\n%systems and not to be used directly for making citations\n")
for R in self:
try:
f.write('\n\n')
f.write(R.bibString(maxLength = maxStringLength, WOSMode = wosMode, restrictedOutput = reducedOutput, niceID = niceIDs))
except BadWOSRecord:
pass
except AttributeError:
raise RecordsNotCompatible("The Record '{}', with ID '{}' does not support writing to bibtext files.".format(R, R.id))
f.close() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'makeDict'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'onlyTheseTags'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'longNames'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'raw'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'numAuthors'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'genderCounts'},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '85', '108', '118', '127', '146', '242']},{'id': '21', 'type': 'if_statement', 'children': ['22', '23', '55']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'onlyTheseTags'},{'id': '23', 'type': 'block', 'children': ['24', '51']},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '33']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'onlyTheseTags'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'if_statement', 'children': ['35', '40']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '39'], 'value': 'in'},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'onlyTheseTags'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'fullToTagDict'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '46']},{'id': '43', 'type': 'subscript', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'onlyTheseTags'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'fullToTagDict'},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'onlyTheseTags'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'retrievedFields'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'onlyTheseTags'},{'id': '55', 'type': 'else_clause', 'children': ['56']},{'id': '56', 'type': 'block', 'children': ['57', '61']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'retrievedFields'},{'id': '60', 'type': 'list', 'children': [], 'value': '[]'},{'id': '61', 'type': 'for_statement', 'children': ['62', '63', '64']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'block', 'children': ['65', '81']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'tagsLst'},{'id': '68', 'type': 'list_comprehension', 'children': ['69', '70', '77']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '70', 'type': 'for_in_clause', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'if_clause', 'children': ['78']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'not'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'retrievedFields'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'augmented_assignment', 'children': ['83', '84'], 'value': '+='},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'retrievedFields'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'tagsLst'},{'id': '85', 'type': 'if_statement', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'longNames'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'try_statement', 'children': ['89', '100']},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'retrievedFields'},{'id': '93', 'type': 'list_comprehension', 'children': ['94', '97']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'tagToFullDict'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '97', 'type': 'for_in_clause', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'retrievedFields'},{'id': '100', 'type': 'except_clause', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'raise_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': '"One of the tags could not be converted to a long name."'},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'retDict'},{'id': '111', 'type': 'dictionary_comprehension', 'children': ['112', '115']},{'id': '112', 'type': 'pair', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '114', 'type': 'list', 'children': [], 'value': '[]'},{'id': '115', 'type': 'for_in_clause', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'retrievedFields'},{'id': '118', 'type': 'if_statement', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'numAuthors'},{'id': '120', 'type': 'block', 'children': ['121']},{'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': 'retDict'},{'id': '125', 'type': 'string', 'children': [], 'value': '"num-Authors"'},{'id': '126', 'type': 'list', 'children': [], 'value': '[]'},{'id': '127', 'type': 'if_statement', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'genderCounts'},{'id': '129', 'type': 'block', 'children': ['130']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'retDict'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '135', 'type': 'argument_list', 'children': ['136']},{'id': '136', 'type': 'dictionary', 'children': ['137', '140', '143']},{'id': '137', 'type': 'pair', 'children': ['138', '139']},{'id': '138', 'type': 'string', 'children': [], 'value': "'num-Male'"},{'id': '139', 'type': 'list', 'children': [], 'value': '[]'},{'id': '140', 'type': 'pair', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': "'num-Female'"},{'id': '142', 'type': 'list', 'children': [], 'value': '[]'},{'id': '143', 'type': 'pair', 'children': ['144', '145']},{'id': '144', 'type': 'string', 'children': [], 'value': "'num-Unknown'"},{'id': '145', 'type': 'list', 'children': [], 'value': '[]'},{'id': '146', 'type': 'for_statement', 'children': ['147', '148', '149']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'block', 'children': ['150', '171', '215']},{'id': '150', 'type': 'if_statement', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'numAuthors'},{'id': '152', 'type': 'block', 'children': ['153']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '160']},{'id': '155', 'type': 'attribute', 'children': ['156', '159']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'retDict'},{'id': '158', 'type': 'string', 'children': [], 'value': '"num-Authors"'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'string', 'children': [], 'value': "'authorsShort'"},{'id': '170', 'type': 'list', 'children': [], 'value': '[]'},{'id': '171', 'type': 'if_statement', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'genderCounts'},{'id': '173', 'type': 'block', 'children': ['174', '188', '197', '206']},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '180']},{'id': '176', 'type': 'pattern_list', 'children': ['177', '178', '179']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'authGenders'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': '_countsTuple'},{'id': '187', 'type': 'True', 'children': []},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '195']},{'id': '190', 'type': 'attribute', 'children': ['191', '194']},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'retDict'},{'id': '193', 'type': 'string', 'children': [], 'value': "'num-Male'"},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '195', 'type': 'argument_list', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '204']},{'id': '199', 'type': 'attribute', 'children': ['200', '203']},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'retDict'},{'id': '202', 'type': 'string', 'children': [], 'value': "'num-Female'"},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'call', 'children': ['208', '213']},{'id': '208', 'type': 'attribute', 'children': ['209', '212']},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'retDict'},{'id': '211', 'type': 'string', 'children': [], 'value': "'num-Unknown'"},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '215', 'type': 'for_statement', 'children': ['216', '219', '232']},{'id': '216', 'type': 'pattern_list', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '219', 'type': 'call', 'children': ['220', '231']},{'id': '220', 'type': 'attribute', 'children': ['221', '230']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'subDict'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'retrievedFields'},{'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'raw'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'raw'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '231', 'type': 'argument_list', 'children': []},{'id': '232', 'type': 'block', 'children': ['233']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '240']},{'id': '235', 'type': 'attribute', 'children': ['236', '239']},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'retDict'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '242', 'type': 'return_statement', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'retDict'} | def makeDict(self, onlyTheseTags = None, longNames = False, raw = False, numAuthors = True, genderCounts = True):
if onlyTheseTags:
for i in range(len(onlyTheseTags)):
if onlyTheseTags[i] in fullToTagDict:
onlyTheseTags[i] = fullToTagDict[onlyTheseTags[i]]
retrievedFields = onlyTheseTags
else:
retrievedFields = []
for R in self:
tagsLst = [t for t in R.keys() if t not in retrievedFields]
retrievedFields += tagsLst
if longNames:
try:
retrievedFields = [tagToFullDict[t] for t in retrievedFields]
except KeyError:
raise KeyError("One of the tags could not be converted to a long name.")
retDict = {k : [] for k in retrievedFields}
if numAuthors:
retDict["num-Authors"] = []
if genderCounts:
retDict.update({'num-Male' : [], 'num-Female' : [], 'num-Unknown' : []})
for R in self:
if numAuthors:
retDict["num-Authors"].append(len(R.get('authorsShort', [])))
if genderCounts:
m, f, u = R.authGenders(_countsTuple = True)
retDict['num-Male'].append(m)
retDict['num-Female'].append(f)
retDict['num-Unknown'].append(u)
for k, v in R.subDict(retrievedFields, raw = raw).items():
retDict[k].append(v)
return retDict |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '44']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'networkCoCitation'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35', '38', '41']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'dropAnon'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '10', 'type': 'string', 'children': [], 'value': '"full"'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'nodeInfo'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'fullInfo'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'weighted'},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dropNonJournals'},{'id': '22', 'type': 'False', 'children': []},{'id': '23', 'type': 'default_parameter', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '25', 'type': 'True', 'children': []},{'id': '26', 'type': 'default_parameter', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'keyWords'},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'detailedCore'},{'id': '31', 'type': 'True', 'children': []},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'detailedCoreAttributes'},{'id': '34', 'type': 'False', 'children': []},{'id': '35', 'type': 'default_parameter', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'coreOnly'},{'id': '37', 'type': 'False', 'children': []},{'id': '38', 'type': 'default_parameter', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'expandedCore'},{'id': '40', 'type': 'False', 'children': []},{'id': '41', 'type': 'default_parameter', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'addCR'},{'id': '43', 'type': 'False', 'children': []},{'id': '44', 'type': 'block', 'children': ['45', '54', '69', '73', '109', '117', '121', '127', '148', '318']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'allowedTypes'},{'id': '48', 'type': 'list', 'children': ['49', '50', '51', '52', '53'], 'value': '["full", "original", "author", "journal", "year"]'},{'id': '49', 'type': 'string', 'children': [], 'value': '"full"'},{'id': '50', 'type': 'string', 'children': [], 'value': '"original"'},{'id': '51', 'type': 'string', 'children': [], 'value': '"author"'},{'id': '52', 'type': 'string', 'children': [], 'value': '"journal"'},{'id': '53', 'type': 'string', 'children': [], 'value': '"year"'},{'id': '54', 'type': 'if_statement', 'children': ['55', '58']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'not'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'allowedTypes'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'raise_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'RCValueError'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'string', 'children': [], 'value': '"{} is not an allowed nodeType."'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'coreValues'},{'id': '72', 'type': 'list', 'children': [], 'value': '[]'},{'id': '73', 'type': 'if_statement', 'children': ['74', '78']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'detailedCore'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'try_statement', 'children': ['80', '95']},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'for_statement', 'children': ['82', '83', '84']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'detailedCore'},{'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': 'coreValues'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'normalizeToTag'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '95', 'type': 'except_clause', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'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': 'coreValues'},{'id': '101', 'type': 'list', 'children': ['102', '103', '104', '105', '106', '107', '108'], 'value': "['id', 'authorsFull', 'year', 'title', 'journal', 'volume', 'beginningPage']"},{'id': '102', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '103', 'type': 'string', 'children': [], 'value': "'authorsFull'"},{'id': '104', 'type': 'string', 'children': [], 'value': "'year'"},{'id': '105', 'type': 'string', 'children': [], 'value': "'title'"},{'id': '106', 'type': 'string', 'children': [], 'value': "'journal'"},{'id': '107', 'type': 'string', 'children': [], 'value': "'volume'"},{'id': '108', 'type': 'string', 'children': [], 'value': "'beginningPage'"},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'tmpgrph'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'Graph'},{'id': '116', 'type': 'argument_list', 'children': []},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'pcount'},{'id': '120', 'type': 'integer', 'children': [], 'value': '0'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'progArgs'},{'id': '124', 'type': 'tuple', 'children': ['125', '126']},{'id': '125', 'type': 'integer', 'children': [], 'value': '0'},{'id': '126', 'type': 'string', 'children': [], 'value': '"Starting to make a co-citation network"'},{'id': '127', 'type': 'if_statement', 'children': ['128', '131', '139']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'metaknowledge'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_MODE'},{'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': 'progKwargs'},{'id': '135', 'type': 'dictionary', 'children': ['136']},{'id': '136', 'type': 'pair', 'children': ['137', '138']},{'id': '137', 'type': 'string', 'children': [], 'value': "'dummy'"},{'id': '138', 'type': 'False', 'children': []},{'id': '139', 'type': 'else_clause', 'children': ['140']},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'progKwargs'},{'id': '144', 'type': 'dictionary', 'children': ['145']},{'id': '145', 'type': 'pair', 'children': ['146', '147']},{'id': '146', 'type': 'string', 'children': [], 'value': "'dummy'"},{'id': '147', 'type': 'True', 'children': []},{'id': '148', 'type': 'with_statement', 'children': ['149', '161']},{'id': '149', 'type': 'with_clause', 'children': ['150']},{'id': '150', 'type': 'with_item', 'children': ['151']},{'id': '151', 'type': 'as_pattern', 'children': ['152', '159']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_ProgressBar'},{'id': '154', 'type': 'argument_list', 'children': ['155', '157']},{'id': '155', 'type': 'list_splat', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'progArgs'},{'id': '157', 'type': 'dictionary_splat', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'progKwargs'},{'id': '159', 'type': 'as_pattern_target', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '161', 'type': 'block', 'children': ['162', '210', '281', '303']},{'id': '162', 'type': 'if_statement', 'children': ['163', '168', '200']},{'id': '163', 'type': 'boolean_operator', 'children': ['164', '167'], 'value': 'or'},{'id': '164', 'type': 'boolean_operator', 'children': ['165', '166'], 'value': 'or'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'coreOnly'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'coreValues'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'expandedCore'},{'id': '168', 'type': 'block', 'children': ['169', '183']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'coreCitesDict'},{'id': '172', 'type': 'dictionary_comprehension', 'children': ['173', '180']},{'id': '173', 'type': 'pair', 'children': ['174', '179']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'createCitation'},{'id': '178', 'type': 'argument_list', 'children': []},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '180', 'type': 'for_in_clause', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '183', 'type': 'if_statement', 'children': ['184', '185', '194']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'coreOnly'},{'id': '185', 'type': 'block', 'children': ['186']},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'coreCites'},{'id': '189', 'type': 'call', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'coreCitesDict'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '193', 'type': 'argument_list', 'children': []},{'id': '194', 'type': 'else_clause', 'children': ['195']},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'coreCites'},{'id': '199', 'type': 'None', 'children': []},{'id': '200', 'type': 'else_clause', 'children': ['201']},{'id': '201', 'type': 'block', 'children': ['202', '206']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'coreCitesDict'},{'id': '205', 'type': 'None', 'children': []},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'coreCites'},{'id': '209', 'type': 'None', 'children': []},{'id': '210', 'type': 'for_statement', 'children': ['211', '212', '213']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'block', 'children': ['214', '239', '248']},{'id': '214', 'type': 'if_statement', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '216', 'type': 'block', 'children': ['217', '221']},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'augmented_assignment', 'children': ['219', '220'], 'value': '+='},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'pcount'},{'id': '220', 'type': 'integer', 'children': [], 'value': '1'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'updateVal'},{'id': '226', 'type': 'argument_list', 'children': ['227', '233']},{'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '/'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'pcount'},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'string', 'children': [], 'value': '"Analyzing: {}"'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'Cites'},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '248', 'type': 'if_statement', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'Cites'},{'id': '250', 'type': 'block', 'children': ['251', '263']},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'filteredCites'},{'id': '254', 'type': 'call', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'filterCites'},{'id': '256', 'type': 'argument_list', 'children': ['257', '258', '259', '260', '261', '262']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'Cites'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'dropAnon'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'dropNonJournals'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'keyWords'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'coreCites'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'addToNetwork'},{'id': '266', 'type': 'argument_list', 'children': ['267', '268', '269', '270', '271', '272', '273', '274', '275', '276', '277', '278']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'tmpgrph'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'filteredCites'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'weighted'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'nodeInfo'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'fullInfo'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'coreCitesDict'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'coreValues'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'detailedCoreAttributes'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'addCR'},{'id': '278', 'type': 'keyword_argument', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'headNd'},{'id': '280', 'type': 'None', 'children': []},{'id': '281', 'type': 'if_statement', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'expandedCore'},{'id': '283', 'type': 'block', 'children': ['284', '295']},{'id': '284', 'type': 'if_statement', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '286', 'type': 'block', 'children': ['287']},{'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': 'PBar'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'updateVal'},{'id': '292', 'type': 'argument_list', 'children': ['293', '294']},{'id': '293', 'type': 'float', 'children': [], 'value': '.98'},{'id': '294', 'type': 'string', 'children': [], 'value': '"Expanding core Records"'},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'call', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'expandRecs'},{'id': '298', 'type': 'argument_list', 'children': ['299', '300', '301', '302']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'tmpgrph'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'weighted'},{'id': '303', 'type': 'if_statement', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '305', 'type': 'block', 'children': ['306']},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'finish'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'call', 'children': ['313', '316']},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'string', 'children': [], 'value': '"Done making a co-citation network from {}"'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '316', 'type': 'argument_list', 'children': ['317']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '318', 'type': 'return_statement', 'children': ['319']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'tmpgrph'} | def networkCoCitation(self, dropAnon = True, nodeType = "full", nodeInfo = True, fullInfo = False, weighted = True, dropNonJournals = False, count = True, keyWords = None, detailedCore = True, detailedCoreAttributes = False, coreOnly = False, expandedCore = False, addCR = False):
allowedTypes = ["full", "original", "author", "journal", "year"]
if nodeType not in allowedTypes:
raise RCValueError("{} is not an allowed nodeType.".format(nodeType))
coreValues = []
if bool(detailedCore):
try:
for tag in detailedCore:
coreValues.append(normalizeToTag(tag))
except TypeError:
coreValues = ['id', 'authorsFull', 'year', 'title', 'journal', 'volume', 'beginningPage']
tmpgrph = nx.Graph()
pcount = 0
progArgs = (0, "Starting to make a co-citation network")
if metaknowledge.VERBOSE_MODE:
progKwargs = {'dummy' : False}
else:
progKwargs = {'dummy' : True}
with _ProgressBar(*progArgs, **progKwargs) as PBar:
if coreOnly or coreValues or expandedCore:
coreCitesDict = {R.createCitation() : R for R in self}
if coreOnly:
coreCites = coreCitesDict.keys()
else:
coreCites = None
else:
coreCitesDict = None
coreCites = None
for R in self:
if PBar:
pcount += 1
PBar.updateVal(pcount / len(self), "Analyzing: {}".format(R))
Cites = R.get('citations')
if Cites:
filteredCites = filterCites(Cites, nodeType, dropAnon, dropNonJournals, keyWords, coreCites)
addToNetwork(tmpgrph, filteredCites, count, weighted, nodeType, nodeInfo , fullInfo, coreCitesDict, coreValues, detailedCoreAttributes, addCR, headNd = None)
if expandedCore:
if PBar:
PBar.updateVal(.98, "Expanding core Records")
expandRecs(tmpgrph, self, nodeType, weighted)
if PBar:
PBar.finish("Done making a co-citation network from {}".format(self))
return tmpgrph |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'networkBibCoupling'},{'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': 'weighted'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'fullInfo'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'addCR'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '21', '42', '325']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'progArgs'},{'id': '18', 'type': 'tuple', 'children': ['19', '20']},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'string', 'children': [], 'value': '"Make a citation network for coupling"'},{'id': '21', 'type': 'if_statement', 'children': ['22', '25', '33']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'metaknowledge'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_MODE'},{'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': 'progKwargs'},{'id': '29', 'type': 'dictionary', 'children': ['30']},{'id': '30', 'type': 'pair', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': "'dummy'"},{'id': '32', 'type': 'False', 'children': []},{'id': '33', 'type': 'else_clause', 'children': ['34']},{'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': 'progKwargs'},{'id': '38', 'type': 'dictionary', 'children': ['39']},{'id': '39', 'type': 'pair', 'children': ['40', '41']},{'id': '40', 'type': 'string', 'children': [], 'value': "'dummy'"},{'id': '41', 'type': 'True', 'children': []},{'id': '42', 'type': 'with_statement', 'children': ['43', '55']},{'id': '43', 'type': 'with_clause', 'children': ['44']},{'id': '44', 'type': 'with_item', 'children': ['45']},{'id': '45', 'type': 'as_pattern', 'children': ['46', '53']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_ProgressBar'},{'id': '48', 'type': 'argument_list', 'children': ['49', '51']},{'id': '49', 'type': 'list_splat', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'progArgs'},{'id': '51', 'type': 'dictionary_splat', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'progKwargs'},{'id': '53', 'type': 'as_pattern_target', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '55', 'type': 'block', 'children': ['56', '88', '92', '99', '107', '115', '121', '189', '193', '200', '313']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'citeGrph'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'networkCitation'},{'id': '63', 'type': 'argument_list', 'children': ['64', '67', '70', '73', '76', '79', '82', '85']},{'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'weighted'},{'id': '66', 'type': 'False', 'children': []},{'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'directed'},{'id': '69', 'type': 'True', 'children': []},{'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'detailedCore'},{'id': '72', 'type': 'True', 'children': []},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'fullInfo'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'fullInfo'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '78', 'type': 'False', 'children': []},{'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'nodeInfo'},{'id': '81', 'type': 'True', 'children': []},{'id': '82', 'type': 'keyword_argument', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'addCR'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'addCR'},{'id': '85', 'type': 'keyword_argument', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': '_quiet'},{'id': '87', 'type': 'True', 'children': []},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'pcount'},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'pmax'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'citeGrph'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'updateVal'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'float', 'children': [], 'value': '.2'},{'id': '106', 'type': 'string', 'children': [], 'value': '"Starting to classify nodes"'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'workingGrph'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'nx'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'Graph'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'couplingSet'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '120', 'type': 'argument_list', 'children': []},{'id': '121', 'type': 'for_statement', 'children': ['122', '125', '133']},{'id': '122', 'type': 'pattern_list', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'citeGrph'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '132', 'type': 'True', 'children': []},{'id': '133', 'type': 'block', 'children': ['134', '138', '158', '172']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'augmented_assignment', 'children': ['136', '137'], 'value': '+='},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'pcount'},{'id': '137', 'type': 'integer', 'children': [], 'value': '1'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'updateVal'},{'id': '143', 'type': 'argument_list', 'children': ['144', '152']},{'id': '144', 'type': 'binary_operator', 'children': ['145', '146'], 'value': '+'},{'id': '145', 'type': 'float', 'children': [], 'value': '.2'},{'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '*'},{'id': '147', 'type': 'float', 'children': [], 'value': '.4'},{'id': '148', 'type': '()', 'children': ['149']},{'id': '149', 'type': 'binary_operator', 'children': ['150', '151'], 'value': '/'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'pcount'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'pmax'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'string', 'children': [], 'value': '"Classifying: {}"'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '158', 'type': 'if_statement', 'children': ['159', '162']},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '161', 'type': 'string', 'children': [], 'value': "'inCore'"},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'call', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'workingGrph'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'add_node'},{'id': '168', 'type': 'argument_list', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '170', 'type': 'dictionary_splat', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '172', 'type': 'if_statement', 'children': ['173', '181']},{'id': '173', 'type': 'comparison_operator', 'children': ['174', '180'], 'value': '>'},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'citeGrph'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'in_degree'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '180', 'type': 'integer', 'children': [], 'value': '0'},{'id': '181', 'type': 'block', 'children': ['182']},{'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': 'couplingSet'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'pcount'},{'id': '192', 'type': 'integer', 'children': [], 'value': '0'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'pmax'},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'couplingSet'},{'id': '200', 'type': 'for_statement', 'children': ['201', '202', '203']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'couplingSet'},{'id': '203', 'type': 'block', 'children': ['204', '224', '236']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'updateVal'},{'id': '209', 'type': 'argument_list', 'children': ['210', '218']},{'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '+'},{'id': '211', 'type': 'float', 'children': [], 'value': '.6'},{'id': '212', 'type': 'binary_operator', 'children': ['213', '214'], 'value': '*'},{'id': '213', 'type': 'float', 'children': [], 'value': '.4'},{'id': '214', 'type': '()', 'children': ['215']},{'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '/'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'pcount'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'pmax'},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'string', 'children': [], 'value': '"Coupling: {}"'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'citesLst'},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'citeGrph'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'in_edges'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '236', 'type': 'for_statement', 'children': ['237', '240', '244']},{'id': '237', 'type': 'pattern_list', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'edgeOuter'},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'citesLst'},{'id': '244', 'type': 'block', 'children': ['245', '251']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'outerNode'},{'id': '248', 'type': 'subscript', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'edgeOuter'},{'id': '250', 'type': 'integer', 'children': [], 'value': '0'},{'id': '251', 'type': 'for_statement', 'children': ['252', '253', '260']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'edgeInner'},{'id': '253', 'type': 'subscript', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'citesLst'},{'id': '255', 'type': 'slice', 'children': ['256', '259']},{'id': '256', 'type': 'binary_operator', 'children': ['257', '258'], 'value': '+'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '258', 'type': 'integer', 'children': [], 'value': '1'},{'id': '259', 'type': 'colon', 'children': []},{'id': '260', 'type': 'block', 'children': ['261', '267']},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'assignment', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'innerNode'},{'id': '264', 'type': 'subscript', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'edgeInner'},{'id': '266', 'type': 'integer', 'children': [], 'value': '0'},{'id': '267', 'type': 'if_statement', 'children': ['268', '277', '289', '303']},{'id': '268', 'type': 'boolean_operator', 'children': ['269', '270'], 'value': 'and'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'weighted'},{'id': '270', 'type': 'call', 'children': ['271', '274']},{'id': '271', 'type': 'attribute', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'workingGrph'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'has_edge'},{'id': '274', 'type': 'argument_list', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'outerNode'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'innerNode'},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'augmented_assignment', 'children': ['280', '288'], 'value': '+='},{'id': '280', 'type': 'subscript', 'children': ['281', '287']},{'id': '281', 'type': 'subscript', 'children': ['282', '285', '286']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'workingGrph'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'outerNode'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'innerNode'},{'id': '287', 'type': 'string', 'children': [], 'value': "'weight'"},{'id': '288', 'type': 'integer', 'children': [], 'value': '1'},{'id': '289', 'type': 'elif_clause', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'weighted'},{'id': '291', 'type': 'block', 'children': ['292']},{'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': 'workingGrph'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '297', 'type': 'argument_list', 'children': ['298', '299', '300']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'outerNode'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'innerNode'},{'id': '300', 'type': 'keyword_argument', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'weight'},{'id': '302', 'type': 'integer', 'children': [], 'value': '1'},{'id': '303', 'type': 'else_clause', 'children': ['304']},{'id': '304', 'type': 'block', 'children': ['305']},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'call', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'workingGrph'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '310', 'type': 'argument_list', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'outerNode'},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'innerNode'},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'finish'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'call', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'string', 'children': [], 'value': '"Done making a bib-coupling network from {}"'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '323', 'type': 'argument_list', 'children': ['324']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '325', 'type': 'return_statement', 'children': ['326']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'workingGrph'} | def networkBibCoupling(self, weighted = True, fullInfo = False, addCR = False):
progArgs = (0, "Make a citation network for coupling")
if metaknowledge.VERBOSE_MODE:
progKwargs = {'dummy' : False}
else:
progKwargs = {'dummy' : True}
with _ProgressBar(*progArgs, **progKwargs) as PBar:
citeGrph = self.networkCitation(weighted = False, directed = True, detailedCore = True, fullInfo = fullInfo, count = False, nodeInfo = True, addCR = addCR, _quiet = True)
pcount = 0
pmax = len(citeGrph)
PBar.updateVal(.2, "Starting to classify nodes")
workingGrph = nx.Graph()
couplingSet = set()
for n, d in citeGrph.nodes(data = True):
pcount += 1
PBar.updateVal(.2 + .4 * (pcount / pmax), "Classifying: {}".format(n))
if d['inCore']:
workingGrph.add_node(n, **d)
if citeGrph.in_degree(n) > 0:
couplingSet.add(n)
pcount = 0
pmax = len(couplingSet)
for n in couplingSet:
PBar.updateVal(.6 + .4 * (pcount / pmax), "Coupling: {}".format(n))
citesLst = list(citeGrph.in_edges(n))
for i, edgeOuter in enumerate(citesLst):
outerNode = edgeOuter[0]
for edgeInner in citesLst[i + 1:]:
innerNode = edgeInner[0]
if weighted and workingGrph.has_edge(outerNode, innerNode):
workingGrph.edges[outerNode, innerNode]['weight'] += 1
elif weighted:
workingGrph.add_edge(outerNode, innerNode, weight = 1)
else:
workingGrph.add_edge(outerNode, innerNode)
PBar.finish("Done making a bib-coupling network from {}".format(self))
return workingGrph |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'localCiteStats'},{'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': 'pandasFriendly'},{'id': '7', 'type': 'False', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'keyType'},{'id': '10', 'type': 'string', 'children': [], 'value': '"citation"'},{'id': '11', 'type': 'block', 'children': ['12', '16', '23', '34', '55', '220']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0'},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'recCount'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'progArgs'},{'id': '26', 'type': 'tuple', 'children': ['27', '28']},{'id': '27', 'type': 'integer', 'children': [], 'value': '0'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'string', 'children': [], 'value': '"Starting to get the local stats on {}s."'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'keyType'},{'id': '34', 'type': 'if_statement', 'children': ['35', '38', '46']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'metaknowledge'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_MODE'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'progKwargs'},{'id': '42', 'type': 'dictionary', 'children': ['43']},{'id': '43', 'type': 'pair', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "'dummy'"},{'id': '45', 'type': 'False', 'children': []},{'id': '46', 'type': 'else_clause', 'children': ['47']},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'progKwargs'},{'id': '51', 'type': 'dictionary', 'children': ['52']},{'id': '52', 'type': 'pair', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "'dummy'"},{'id': '54', 'type': 'True', 'children': []},{'id': '55', 'type': 'with_statement', 'children': ['56', '68']},{'id': '56', 'type': 'with_clause', 'children': ['57']},{'id': '57', 'type': 'with_item', 'children': ['58']},{'id': '58', 'type': 'as_pattern', 'children': ['59', '66']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_ProgressBar'},{'id': '61', 'type': 'argument_list', 'children': ['62', '64']},{'id': '62', 'type': 'list_splat', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'progArgs'},{'id': '64', 'type': 'dictionary_splat', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'progKwargs'},{'id': '66', 'type': 'as_pattern_target', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '68', 'type': 'block', 'children': ['69', '77', '81', '111', '201']},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'keyTypesLst'},{'id': '72', 'type': 'list', 'children': ['73', '74', '75', '76'], 'value': '["citation", "journal", "year", "author"]'},{'id': '73', 'type': 'string', 'children': [], 'value': '"citation"'},{'id': '74', 'type': 'string', 'children': [], 'value': '"journal"'},{'id': '75', 'type': 'string', 'children': [], 'value': '"year"'},{'id': '76', 'type': 'string', 'children': [], 'value': '"author"'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'citesDict'},{'id': '80', 'type': 'dictionary', 'children': []},{'id': '81', 'type': 'if_statement', 'children': ['82', '85']},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'not'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'keyType'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'keyTypesLst'},{'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': 'TypeError'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'string', 'children': [], 'value': '"{} is not a valid key type, only \'{}\' or \'{}\' are."'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96', '107']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'keyType'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'string', 'children': [], 'value': '"\', \'"'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'keyTypesLst'},{'id': '103', 'type': 'slice', 'children': ['104', '105']},{'id': '104', 'type': 'colon', 'children': []},{'id': '105', 'type': 'unary_operator', 'children': ['106'], 'value': '-'},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'keyTypesLst'},{'id': '109', 'type': 'unary_operator', 'children': ['110'], 'value': '-'},{'id': '110', 'type': 'integer', 'children': [], 'value': '1'},{'id': '111', 'type': 'for_statement', 'children': ['112', '113', '114']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '114', 'type': 'block', 'children': ['115', '124', '148']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'rCites'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '124', 'type': 'if_statement', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '126', 'type': 'block', 'children': ['127', '131']},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'augmented_assignment', 'children': ['129', '130'], 'value': '+='},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'updateVal'},{'id': '136', 'type': 'argument_list', 'children': ['137', '140']},{'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '/'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'recCount'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'string', 'children': [], 'value': '"Analysing: {}"'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'UT'},{'id': '148', 'type': 'if_statement', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'rCites'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'for_statement', 'children': ['152', '153', '154']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'rCites'},{'id': '154', 'type': 'block', 'children': ['155', '182']},{'id': '155', 'type': 'if_statement', 'children': ['156', '161', '166']},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': '=='},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'keyType'},{'id': '158', 'type': 'subscript', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'keyTypesLst'},{'id': '160', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'cVal'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168', '176']},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'cVal'},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'keyType'},{'id': '176', 'type': 'if_statement', 'children': ['177', '180']},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'is'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'cVal'},{'id': '179', 'type': 'None', 'children': []},{'id': '180', 'type': 'block', 'children': ['181']},{'id': '181', 'type': 'continue_statement', 'children': []},{'id': '182', 'type': 'if_statement', 'children': ['183', '186', '193']},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': 'in'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'cVal'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'citesDict'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'augmented_assignment', 'children': ['189', '192'], 'value': '+='},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'citesDict'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'cVal'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1'},{'id': '193', 'type': 'else_clause', 'children': ['194']},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'expression_statement', 'children': ['196']},{'id': '196', 'type': 'assignment', 'children': ['197', '200']},{'id': '197', 'type': 'subscript', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'citesDict'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'cVal'},{'id': '200', 'type': 'integer', 'children': [], 'value': '1'},{'id': '201', 'type': 'if_statement', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'finish'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'string', 'children': [], 'value': '"Done, {} {} fields analysed"'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '214', 'type': 'argument_list', 'children': ['215', '219']},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '217', 'type': 'argument_list', 'children': ['218']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'citesDict'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'keyType'},{'id': '220', 'type': 'if_statement', 'children': ['221', '222', '263']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'pandasFriendly'},{'id': '222', 'type': 'block', 'children': ['223', '227', '231', '255']},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'citeLst'},{'id': '226', 'type': 'list', 'children': [], 'value': '[]'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'countLst'},{'id': '230', 'type': 'list', 'children': [], 'value': '[]'},{'id': '231', 'type': 'for_statement', 'children': ['232', '235', '240']},{'id': '232', 'type': 'pattern_list', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'occ'},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'citesDict'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '239', 'type': 'argument_list', 'children': []},{'id': '240', 'type': 'block', 'children': ['241', '248']},{'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': 'citeLst'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'cite'},{'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': 'countLst'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'occ'},{'id': '255', 'type': 'return_statement', 'children': ['256']},{'id': '256', 'type': 'dictionary', 'children': ['257', '260']},{'id': '257', 'type': 'pair', 'children': ['258', '259']},{'id': '258', 'type': 'string', 'children': [], 'value': '"Citations"'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'citeLst'},{'id': '260', 'type': 'pair', 'children': ['261', '262']},{'id': '261', 'type': 'string', 'children': [], 'value': '"Counts"'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'countLst'},{'id': '263', 'type': 'else_clause', 'children': ['264']},{'id': '264', 'type': 'block', 'children': ['265']},{'id': '265', 'type': 'return_statement', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'citesDict'} | def localCiteStats(self, pandasFriendly = False, keyType = "citation"):
count = 0
recCount = len(self)
progArgs = (0, "Starting to get the local stats on {}s.".format(keyType))
if metaknowledge.VERBOSE_MODE:
progKwargs = {'dummy' : False}
else:
progKwargs = {'dummy' : True}
with _ProgressBar(*progArgs, **progKwargs) as PBar:
keyTypesLst = ["citation", "journal", "year", "author"]
citesDict = {}
if keyType not in keyTypesLst:
raise TypeError("{} is not a valid key type, only '{}' or '{}' are.".format(keyType, "', '".join(keyTypesLst[:-1]), keyTypesLst[-1]))
for R in self:
rCites = R.get('citations')
if PBar:
count += 1
PBar.updateVal(count / recCount, "Analysing: {}".format(R.UT))
if rCites:
for c in rCites:
if keyType == keyTypesLst[0]:
cVal = c
else:
cVal = getattr(c, keyType)
if cVal is None:
continue
if cVal in citesDict:
citesDict[cVal] += 1
else:
citesDict[cVal] = 1
if PBar:
PBar.finish("Done, {} {} fields analysed".format(len(citesDict), keyType))
if pandasFriendly:
citeLst = []
countLst = []
for cite, occ in citesDict.items():
citeLst.append(cite)
countLst.append(occ)
return {"Citations" : citeLst, "Counts" : countLst}
else:
return citesDict |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'citeFilter'},{'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': 'keyString'},{'id': '7', 'type': 'string', 'children': [], 'value': "''"},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '10', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'caseSensitive'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '22', '29', '389']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'retRecs'},{'id': '21', 'type': 'list', 'children': [], 'value': '[]'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'keyString'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'keyString'},{'id': '29', 'type': 'for_statement', 'children': ['30', '31', '32']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'try_statement', 'children': ['34', '385']},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'if_statement', 'children': ['36', '39', '92', '135', '174', '212', '251', '290', '329', '358']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': '=='},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '38', 'type': 'string', 'children': [], 'value': "'all'"},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'for_statement', 'children': ['41', '42', '48']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'if_statement', 'children': ['50', '51', '67']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'caseSensitive'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'if_statement', 'children': ['53', '58']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'in'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'keyString'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'original'},{'id': '58', 'type': 'block', 'children': ['59', '66']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'retRecs'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '66', 'type': 'break_statement', 'children': []},{'id': '67', 'type': 'else_clause', 'children': ['68']},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'if_statement', 'children': ['70', '83']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '76'], 'value': 'in'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'keyString'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'call', 'children': ['77', '82']},{'id': '77', 'type': 'attribute', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'original'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '82', 'type': 'argument_list', 'children': []},{'id': '83', 'type': 'block', 'children': ['84', '91']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'retRecs'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '91', 'type': 'break_statement', 'children': []},{'id': '92', 'type': 'elif_clause', 'children': ['93', '96']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': '=='},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '95', 'type': 'string', 'children': [], 'value': "'author'"},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'for_statement', 'children': ['98', '99', '105']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '105', 'type': 'block', 'children': ['106']},{'id': '106', 'type': 'try_statement', 'children': ['107', '131']},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'if_statement', 'children': ['109', '122']},{'id': '109', 'type': 'comparison_operator', 'children': ['110', '115'], 'value': 'in'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'keyString'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'call', 'children': ['116', '121']},{'id': '116', 'type': 'attribute', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'author'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '121', 'type': 'argument_list', 'children': []},{'id': '122', 'type': 'block', 'children': ['123', '130']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'retRecs'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '130', 'type': 'break_statement', 'children': []},{'id': '131', 'type': 'except_clause', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'pass_statement', 'children': []},{'id': '135', 'type': 'elif_clause', 'children': ['136', '139']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': '=='},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '138', 'type': 'string', 'children': [], 'value': "'journal'"},{'id': '139', 'type': 'block', 'children': ['140']},{'id': '140', 'type': 'for_statement', 'children': ['141', '142', '148']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'try_statement', 'children': ['150', '170']},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'if_statement', 'children': ['152', '161']},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '158'], 'value': 'in'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'keyString'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'journal'},{'id': '161', 'type': 'block', 'children': ['162', '169']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'retRecs'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '169', 'type': 'break_statement', 'children': []},{'id': '170', 'type': 'except_clause', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'pass_statement', 'children': []},{'id': '174', 'type': 'elif_clause', 'children': ['175', '178']},{'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': '=='},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '177', 'type': 'string', 'children': [], 'value': "'year'"},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'for_statement', 'children': ['180', '181', '187']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'try_statement', 'children': ['189', '208']},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'if_statement', 'children': ['191', '199']},{'id': '191', 'type': 'comparison_operator', 'children': ['192', '196'], 'value': '=='},{'id': '192', 'type': 'call', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'keyString'},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '199', 'type': 'block', 'children': ['200', '207']},{'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': 'retRecs'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '207', 'type': 'break_statement', 'children': []},{'id': '208', 'type': 'except_clause', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '210', 'type': 'block', 'children': ['211']},{'id': '211', 'type': 'pass_statement', 'children': []},{'id': '212', 'type': 'elif_clause', 'children': ['213', '216']},{'id': '213', 'type': 'comparison_operator', 'children': ['214', '215'], 'value': '=='},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '215', 'type': 'string', 'children': [], 'value': "'V'"},{'id': '216', 'type': 'block', 'children': ['217']},{'id': '217', 'type': 'for_statement', 'children': ['218', '219', '225']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '219', 'type': 'call', 'children': ['220', '223']},{'id': '220', 'type': 'attribute', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '225', 'type': 'block', 'children': ['226']},{'id': '226', 'type': 'try_statement', 'children': ['227', '247']},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'if_statement', 'children': ['229', '238']},{'id': '229', 'type': 'comparison_operator', 'children': ['230', '235'], 'value': 'in'},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'keyString'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '234', 'type': 'argument_list', 'children': []},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'V'},{'id': '238', 'type': 'block', 'children': ['239', '246']},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'retRecs'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '246', 'type': 'break_statement', 'children': []},{'id': '247', 'type': 'except_clause', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'pass_statement', 'children': []},{'id': '251', 'type': 'elif_clause', 'children': ['252', '255']},{'id': '252', 'type': 'comparison_operator', 'children': ['253', '254'], 'value': '=='},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '254', 'type': 'string', 'children': [], 'value': "'P'"},{'id': '255', 'type': 'block', 'children': ['256']},{'id': '256', 'type': 'for_statement', 'children': ['257', '258', '264']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '258', 'type': 'call', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '264', 'type': 'block', 'children': ['265']},{'id': '265', 'type': 'try_statement', 'children': ['266', '286']},{'id': '266', 'type': 'block', 'children': ['267']},{'id': '267', 'type': 'if_statement', 'children': ['268', '277']},{'id': '268', 'type': 'comparison_operator', 'children': ['269', '274'], 'value': 'in'},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'keyString'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '273', 'type': 'argument_list', 'children': []},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'P'},{'id': '277', 'type': 'block', 'children': ['278', '285']},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'call', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'retRecs'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '285', 'type': 'break_statement', 'children': []},{'id': '286', 'type': 'except_clause', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '288', 'type': 'block', 'children': ['289']},{'id': '289', 'type': 'pass_statement', 'children': []},{'id': '290', 'type': 'elif_clause', 'children': ['291', '294']},{'id': '291', 'type': 'comparison_operator', 'children': ['292', '293'], 'value': '=='},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '293', 'type': 'string', 'children': [], 'value': "'misc'"},{'id': '294', 'type': 'block', 'children': ['295']},{'id': '295', 'type': 'for_statement', 'children': ['296', '297', '303']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '297', 'type': 'call', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '303', 'type': 'block', 'children': ['304']},{'id': '304', 'type': 'try_statement', 'children': ['305', '325']},{'id': '305', 'type': 'block', 'children': ['306']},{'id': '306', 'type': 'if_statement', 'children': ['307', '316']},{'id': '307', 'type': 'comparison_operator', 'children': ['308', '313'], 'value': 'in'},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'keyString'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '312', 'type': 'argument_list', 'children': []},{'id': '313', 'type': 'attribute', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'misc'},{'id': '316', 'type': 'block', 'children': ['317', '324']},{'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': 'retRecs'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '322', 'type': 'argument_list', 'children': ['323']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '324', 'type': 'break_statement', 'children': []},{'id': '325', 'type': 'except_clause', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '327', 'type': 'block', 'children': ['328']},{'id': '328', 'type': 'pass_statement', 'children': []},{'id': '329', 'type': 'elif_clause', 'children': ['330', '333']},{'id': '330', 'type': 'comparison_operator', 'children': ['331', '332'], 'value': '=='},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '332', 'type': 'string', 'children': [], 'value': "'anonymous'"},{'id': '333', 'type': 'block', 'children': ['334']},{'id': '334', 'type': 'for_statement', 'children': ['335', '336', '342']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '336', 'type': 'call', 'children': ['337', '340']},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '340', 'type': 'argument_list', 'children': ['341']},{'id': '341', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '342', 'type': 'block', 'children': ['343']},{'id': '343', 'type': 'if_statement', 'children': ['344', '349']},{'id': '344', 'type': 'call', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'isAnonymous'},{'id': '348', 'type': 'argument_list', 'children': []},{'id': '349', 'type': 'block', 'children': ['350', '357']},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'call', 'children': ['352', '355']},{'id': '352', 'type': 'attribute', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'retRecs'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '355', 'type': 'argument_list', 'children': ['356']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '357', 'type': 'break_statement', 'children': []},{'id': '358', 'type': 'elif_clause', 'children': ['359', '362']},{'id': '359', 'type': 'comparison_operator', 'children': ['360', '361'], 'value': '=='},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '361', 'type': 'string', 'children': [], 'value': "'bad'"},{'id': '362', 'type': 'block', 'children': ['363']},{'id': '363', 'type': 'for_statement', 'children': ['364', '365', '371']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '371', 'type': 'block', 'children': ['372']},{'id': '372', 'type': 'if_statement', 'children': ['373', '376']},{'id': '373', 'type': 'attribute', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'bad'},{'id': '376', 'type': 'block', 'children': ['377', '384']},{'id': '377', 'type': 'expression_statement', 'children': ['378']},{'id': '378', 'type': 'call', 'children': ['379', '382']},{'id': '379', 'type': 'attribute', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'retRecs'},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '382', 'type': 'argument_list', 'children': ['383']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '384', 'type': 'break_statement', 'children': []},{'id': '385', 'type': 'except_clause', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '387', 'type': 'block', 'children': ['388']},{'id': '388', 'type': 'pass_statement', 'children': []},{'id': '389', 'type': 'if_statement', 'children': ['390', '391', '427']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '391', 'type': 'block', 'children': ['392', '396', '412']},{'id': '392', 'type': 'expression_statement', 'children': ['393']},{'id': '393', 'type': 'assignment', 'children': ['394', '395']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '395', 'type': 'list', 'children': [], 'value': '[]'},{'id': '396', 'type': 'for_statement', 'children': ['397', '398', '399']},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '399', 'type': 'block', 'children': ['400']},{'id': '400', 'type': 'if_statement', 'children': ['401', '404']},{'id': '401', 'type': 'comparison_operator', 'children': ['402', '403'], 'value': 'not'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'retRecs'},{'id': '404', 'type': 'block', 'children': ['405']},{'id': '405', 'type': 'expression_statement', 'children': ['406']},{'id': '406', 'type': 'call', 'children': ['407', '410']},{'id': '407', 'type': 'attribute', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '410', 'type': 'argument_list', 'children': ['411']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '412', 'type': 'return_statement', 'children': ['413']},{'id': '413', 'type': 'call', 'children': ['414', '415']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'RecordCollection'},{'id': '415', 'type': 'argument_list', 'children': ['416', '419', '424']},{'id': '416', 'type': 'keyword_argument', 'children': ['417', '418']},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'inCollection'},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'excluded'},{'id': '419', 'type': 'keyword_argument', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '421', 'type': 'attribute', 'children': ['422', '423']},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '423', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '424', 'type': 'keyword_argument', 'children': ['425', '426']},{'id': '425', 'type': 'identifier', 'children': [], 'value': 'quietStart'},{'id': '426', 'type': 'True', 'children': []},{'id': '427', 'type': 'else_clause', 'children': ['428']},{'id': '428', 'type': 'block', 'children': ['429']},{'id': '429', 'type': 'return_statement', 'children': ['430']},{'id': '430', 'type': 'call', 'children': ['431', '432']},{'id': '431', 'type': 'identifier', 'children': [], 'value': 'RecordCollection'},{'id': '432', 'type': 'argument_list', 'children': ['433', '436', '441']},{'id': '433', 'type': 'keyword_argument', 'children': ['434', '435']},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'inCollection'},{'id': '435', 'type': 'identifier', 'children': [], 'value': 'retRecs'},{'id': '436', 'type': 'keyword_argument', 'children': ['437', '438']},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '438', 'type': 'attribute', 'children': ['439', '440']},{'id': '439', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '441', 'type': 'keyword_argument', 'children': ['442', '443']},{'id': '442', 'type': 'identifier', 'children': [], 'value': 'quietStart'},{'id': '443', 'type': 'True', 'children': []} | def citeFilter(self, keyString = '', field = 'all', reverse = False, caseSensitive = False):
retRecs = []
keyString = str(keyString)
for R in self:
try:
if field == 'all':
for cite in R.get('citations'):
if caseSensitive:
if keyString in cite.original:
retRecs.append(R)
break
else:
if keyString.upper() in cite.original.upper():
retRecs.append(R)
break
elif field == 'author':
for cite in R.get('citations'):
try:
if keyString.upper() in cite.author.upper():
retRecs.append(R)
break
except AttributeError:
pass
elif field == 'journal':
for cite in R.get('citations'):
try:
if keyString.upper() in cite.journal:
retRecs.append(R)
break
except AttributeError:
pass
elif field == 'year':
for cite in R.get('citations'):
try:
if int(keyString) == cite.year:
retRecs.append(R)
break
except AttributeError:
pass
elif field == 'V':
for cite in R.get('citations'):
try:
if keyString.upper() in cite.V:
retRecs.append(R)
break
except AttributeError:
pass
elif field == 'P':
for cite in R.get('citations'):
try:
if keyString.upper() in cite.P:
retRecs.append(R)
break
except AttributeError:
pass
elif field == 'misc':
for cite in R.get('citations'):
try:
if keyString.upper() in cite.misc:
retRecs.append(R)
break
except AttributeError:
pass
elif field == 'anonymous':
for cite in R.get('citations'):
if cite.isAnonymous():
retRecs.append(R)
break
elif field == 'bad':
for cite in R.get('citations'):
if cite.bad:
retRecs.append(R)
break
except TypeError:
pass
if reverse:
excluded = []
for R in self:
if R not in retRecs:
excluded.append(R)
return RecordCollection(inCollection = excluded, name = self.name, quietStart = True)
else:
return RecordCollection(inCollection = retRecs, name = self.name, quietStart = True) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '24']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'rankedSeries'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'outputFile'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'giveCounts'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'giveRanks'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'greatestFirst'},{'id': '17', 'type': 'True', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'pandasMode'},{'id': '20', 'type': 'True', 'children': []},{'id': '21', 'type': 'default_parameter', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'limitTo'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25', '35', '39', '99', '121', '169']},{'id': '25', 'type': 'if_statement', 'children': ['26', '29']},{'id': '26', 'type': 'boolean_operator', 'children': ['27', '28'], 'value': 'and'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'giveRanks'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'giveCounts'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'raise_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'mkException'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': '"rankedSeries cannot return counts and ranks only one of giveRanks or giveCounts can be True."'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '38', 'type': 'dictionary', 'children': []},{'id': '39', 'type': 'for_statement', 'children': ['40', '41', '42']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'block', 'children': ['43', '55', '68']},{'id': '43', 'type': 'try_statement', 'children': ['44', '51']},{'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': 'val'},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '51', 'type': 'except_clause', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '53', 'type': 'block', 'children': ['54']},{'id': '54', 'type': 'continue_statement', 'children': []},{'id': '55', 'type': 'if_statement', 'children': ['56', '62']},{'id': '56', 'type': 'not_operator', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '66', 'type': 'list', 'children': ['67'], 'value': '[val]'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '68', 'type': 'for_statement', 'children': ['69', '70', '71']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '71', 'type': 'block', 'children': ['72', '80']},{'id': '72', 'type': 'if_statement', 'children': ['73', '78']},{'id': '73', 'type': 'boolean_operator', 'children': ['74', '75'], 'value': 'and'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'limitTo'},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'not'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'limitTo'},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'continue_statement', 'children': []},{'id': '80', 'type': 'if_statement', 'children': ['81', '84', '91']},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': 'in'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'augmented_assignment', 'children': ['87', '90'], 'value': '+='},{'id': '87', 'type': 'subscript', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '90', 'type': 'integer', 'children': [], 'value': '1'},{'id': '91', 'type': 'else_clause', 'children': ['92']},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '98']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '98', 'type': 'integer', 'children': [], 'value': '1'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'seriesList'},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '104', 'type': 'argument_list', 'children': ['105', '110', '118']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '109', 'type': 'argument_list', 'children': []},{'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '112', 'type': 'lambda', 'children': ['113', '115']},{'id': '113', 'type': 'lambda_parameters', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'greatestFirst'},{'id': '121', 'type': 'if_statement', 'children': ['122', '125']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'is'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'outputFile'},{'id': '124', 'type': 'None', 'children': []},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'with_statement', 'children': ['127', '137']},{'id': '127', 'type': 'with_clause', 'children': ['128']},{'id': '128', 'type': 'with_item', 'children': ['129']},{'id': '129', 'type': 'as_pattern', 'children': ['130', '135']},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '132', 'type': 'argument_list', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'outputFile'},{'id': '134', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '135', 'type': 'as_pattern_target', 'children': ['136']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '137', 'type': 'block', 'children': ['138', '150', '162']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'csv'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '145', 'type': 'argument_list', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '149', 'type': 'string', 'children': [], 'value': "'excel'"},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'writerow'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'tuple', 'children': ['157', '161']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '161', 'type': 'string', 'children': [], 'value': "'count'"},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'writerows'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'seriesList'},{'id': '169', 'type': 'if_statement', 'children': ['170', '174', '177', '308']},{'id': '170', 'type': 'boolean_operator', 'children': ['171', '172'], 'value': 'and'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'giveCounts'},{'id': '172', 'type': 'not_operator', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'pandasMode'},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'return_statement', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'seriesList'},{'id': '177', 'type': 'elif_clause', 'children': ['178', '181']},{'id': '178', 'type': 'boolean_operator', 'children': ['179', '180'], 'value': 'or'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'giveRanks'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'pandasMode'},{'id': '181', 'type': 'block', 'children': ['182', '192', '196', '200', '213', '289', '299']},{'id': '182', 'type': 'if_statement', 'children': ['183', '185']},{'id': '183', 'type': 'not_operator', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'greatestFirst'},{'id': '185', 'type': 'block', 'children': ['186']},{'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': 'seriesList'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '191', 'type': 'argument_list', 'children': []},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'currentRank'},{'id': '195', 'type': 'integer', 'children': [], 'value': '1'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'retList'},{'id': '199', 'type': 'list', 'children': [], 'value': '[]'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'panDict'},{'id': '203', 'type': 'dictionary', 'children': ['204', '207', '210']},{'id': '204', 'type': 'pair', 'children': ['205', '206']},{'id': '205', 'type': 'string', 'children': [], 'value': "'entry'"},{'id': '206', 'type': 'list', 'children': [], 'value': '[]'},{'id': '207', 'type': 'pair', 'children': ['208', '209']},{'id': '208', 'type': 'string', 'children': [], 'value': "'count'"},{'id': '209', 'type': 'list', 'children': [], 'value': '[]'},{'id': '210', 'type': 'pair', 'children': ['211', '212']},{'id': '211', 'type': 'string', 'children': [], 'value': "'rank'"},{'id': '212', 'type': 'list', 'children': [], 'value': '[]'},{'id': '213', 'type': 'try_statement', 'children': ['214', '223', '227']},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'currentCount'},{'id': '218', 'type': 'subscript', 'children': ['219', '222']},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'seriesList'},{'id': '221', 'type': 'integer', 'children': [], 'value': '0'},{'id': '222', 'type': 'integer', 'children': [], 'value': '1'},{'id': '223', 'type': 'except_clause', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'IndexError'},{'id': '225', 'type': 'block', 'children': ['226']},{'id': '226', 'type': 'pass_statement', 'children': []},{'id': '227', 'type': 'else_clause', 'children': ['228']},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'for_statement', 'children': ['230', '233', '234']},{'id': '230', 'type': 'pattern_list', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'valString'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'seriesList'},{'id': '234', 'type': 'block', 'children': ['235', '248']},{'id': '235', 'type': 'if_statement', 'children': ['236', '239']},{'id': '236', 'type': 'comparison_operator', 'children': ['237', '238'], 'value': '>'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'currentCount'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '239', 'type': 'block', 'children': ['240', '244']},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'augmented_assignment', 'children': ['242', '243'], 'value': '+='},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'currentRank'},{'id': '243', 'type': 'integer', 'children': [], 'value': '1'},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'currentCount'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '248', 'type': 'if_statement', 'children': ['249', '250', '278']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'pandasMode'},{'id': '250', 'type': 'block', 'children': ['251', '260', '269']},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'call', 'children': ['253', '258']},{'id': '253', 'type': 'attribute', 'children': ['254', '257']},{'id': '254', 'type': 'subscript', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'panDict'},{'id': '256', 'type': 'string', 'children': [], 'value': "'entry'"},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '258', 'type': 'argument_list', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'valString'},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'call', 'children': ['262', '267']},{'id': '262', 'type': 'attribute', 'children': ['263', '266']},{'id': '263', 'type': 'subscript', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'panDict'},{'id': '265', 'type': 'string', 'children': [], 'value': "'count'"},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '276']},{'id': '271', 'type': 'attribute', 'children': ['272', '275']},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'panDict'},{'id': '274', 'type': 'string', 'children': [], 'value': "'rank'"},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '276', 'type': 'argument_list', 'children': ['277']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'currentRank'},{'id': '278', 'type': 'else_clause', 'children': ['279']},{'id': '279', 'type': 'block', 'children': ['280']},{'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': 'retList'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'tuple', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'valString'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'currentRank'},{'id': '289', 'type': 'if_statement', 'children': ['290', '292']},{'id': '290', 'type': 'not_operator', 'children': ['291']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'greatestFirst'},{'id': '292', 'type': 'block', 'children': ['293']},{'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': 'retList'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '298', 'type': 'argument_list', 'children': []},{'id': '299', 'type': 'if_statement', 'children': ['300', '301', '304']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'pandasMode'},{'id': '301', 'type': 'block', 'children': ['302']},{'id': '302', 'type': 'return_statement', 'children': ['303']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'panDict'},{'id': '304', 'type': 'else_clause', 'children': ['305']},{'id': '305', 'type': 'block', 'children': ['306']},{'id': '306', 'type': 'return_statement', 'children': ['307']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'retList'},{'id': '308', 'type': 'else_clause', 'children': ['309']},{'id': '309', 'type': 'block', 'children': ['310']},{'id': '310', 'type': 'return_statement', 'children': ['311']},{'id': '311', 'type': 'list_comprehension', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '313', 'type': 'for_in_clause', 'children': ['314', '317']},{'id': '314', 'type': 'pattern_list', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'seriesList'} | def rankedSeries(self, tag, outputFile = None, giveCounts = True, giveRanks = False, greatestFirst = True, pandasMode = True, limitTo = None):
if giveRanks and giveCounts:
raise mkException("rankedSeries cannot return counts and ranks only one of giveRanks or giveCounts can be True.")
seriesDict = {}
for R in self:
try:
val = R[tag]
except KeyError:
continue
if not isinstance(val, list):
val = [val]
for entry in val:
if limitTo and entry not in limitTo:
continue
if entry in seriesDict:
seriesDict[entry] += 1
else:
seriesDict[entry] = 1
seriesList = sorted(seriesDict.items(), key = lambda x: x[1], reverse = greatestFirst)
if outputFile is not None:
with open(outputFile, 'w') as f:
writer = csv.writer(f, dialect = 'excel')
writer.writerow((str(tag), 'count'))
writer.writerows(seriesList)
if giveCounts and not pandasMode:
return seriesList
elif giveRanks or pandasMode:
if not greatestFirst:
seriesList.reverse()
currentRank = 1
retList = []
panDict = {'entry' : [], 'count' : [], 'rank' : []}
try:
currentCount = seriesList[0][1]
except IndexError:
pass
else:
for valString, count in seriesList:
if currentCount > count:
currentRank += 1
currentCount = count
if pandasMode:
panDict['entry'].append(valString)
panDict['count'].append(count)
panDict['rank'].append(currentRank)
else:
retList.append((valString, currentRank))
if not greatestFirst:
retList.reverse()
if pandasMode:
return panDict
else:
return retList
else:
return [e for e,c in seriesList] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'timeSeries'},{'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': 'tag'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'outputFile'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'giveYears'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'greatestFirst'},{'id': '16', 'type': 'True', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'limitTo'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'pandasMode'},{'id': '22', 'type': 'True', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '28', '134', '138', '162', '180', '252']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '27', 'type': 'dictionary', 'children': []},{'id': '28', 'type': 'for_statement', 'children': ['29', '30', '31']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'block', 'children': ['32', '44']},{'id': '32', 'type': 'try_statement', 'children': ['33', '40']},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '39', 'type': 'string', 'children': [], 'value': "'year'"},{'id': '40', 'type': 'except_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'continue_statement', 'children': []},{'id': '44', 'type': 'if_statement', 'children': ['45', '48', '58']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'is'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '47', 'type': 'None', 'children': []},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '54']},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '54', 'type': 'dictionary', 'children': ['55']},{'id': '55', 'type': 'pair', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '57', 'type': 'integer', 'children': [], 'value': '1'},{'id': '58', 'type': 'else_clause', 'children': ['59']},{'id': '59', 'type': 'block', 'children': ['60', '72', '85']},{'id': '60', 'type': 'try_statement', 'children': ['61', '68']},{'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': 'val'},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '68', 'type': 'except_clause', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'continue_statement', 'children': []},{'id': '72', 'type': 'if_statement', 'children': ['73', '79']},{'id': '73', 'type': 'not_operator', 'children': ['74']},{'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': 'val'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '83', 'type': 'list', 'children': ['84'], 'value': '[val]'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '85', 'type': 'for_statement', 'children': ['86', '87', '88']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '88', 'type': 'block', 'children': ['89', '97']},{'id': '89', 'type': 'if_statement', 'children': ['90', '95']},{'id': '90', 'type': 'boolean_operator', 'children': ['91', '92'], 'value': 'and'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'limitTo'},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'not'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'limitTo'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'continue_statement', 'children': []},{'id': '97', 'type': 'if_statement', 'children': ['98', '101', '123']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'in'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'try_statement', 'children': ['103', '112']},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'augmented_assignment', 'children': ['106', '111'], 'value': '+='},{'id': '106', 'type': 'subscript', 'children': ['107', '110']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '111', 'type': 'integer', 'children': [], 'value': '1'},{'id': '112', 'type': 'except_clause', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '122']},{'id': '117', 'type': 'subscript', 'children': ['118', '121']},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '122', 'type': 'integer', 'children': [], 'value': '1'},{'id': '123', 'type': 'else_clause', 'children': ['124']},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '130']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '130', 'type': 'dictionary', 'children': ['131']},{'id': '131', 'type': 'pair', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '133', 'type': 'integer', 'children': [], 'value': '1'},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'seriesList'},{'id': '137', 'type': 'list', 'children': [], 'value': '[]'},{'id': '138', 'type': 'for_statement', 'children': ['139', '142', '147']},{'id': '139', 'type': 'pattern_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'yd'},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '146', 'type': 'argument_list', 'children': []},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'augmented_assignment', 'children': ['150', '151'], 'value': '+='},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'seriesList'},{'id': '151', 'type': 'list_comprehension', 'children': ['152', '155']},{'id': '152', 'type': 'tuple', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '155', 'type': 'for_in_clause', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'yd'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '161', 'type': 'argument_list', 'children': []},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'seriesList'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '167', 'type': 'argument_list', 'children': ['168', '169', '177']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'seriesList'},{'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '171', 'type': 'lambda', 'children': ['172', '174']},{'id': '172', 'type': 'lambda_parameters', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '174', 'type': 'subscript', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '176', 'type': 'integer', 'children': [], 'value': '1'},{'id': '177', 'type': 'keyword_argument', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'greatestFirst'},{'id': '180', 'type': 'if_statement', 'children': ['181', '184']},{'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': 'is'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'outputFile'},{'id': '183', 'type': 'None', 'children': []},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'with_statement', 'children': ['186', '196']},{'id': '186', 'type': 'with_clause', 'children': ['187']},{'id': '187', 'type': 'with_item', 'children': ['188']},{'id': '188', 'type': 'as_pattern', 'children': ['189', '194']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'outputFile'},{'id': '193', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '194', 'type': 'as_pattern_target', 'children': ['195']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '196', 'type': 'block', 'children': ['197', '209', '221']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'csv'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'dialect'},{'id': '208', 'type': 'string', 'children': [], 'value': "'excel'"},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'writerow'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'tuple', 'children': ['216', '220']},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '220', 'type': 'string', 'children': [], 'value': "'years'"},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'call', 'children': ['223', '226']},{'id': '223', 'type': 'attribute', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'writer'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'writerows'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'generator_expression', 'children': ['228', '243']},{'id': '228', 'type': 'tuple', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'string', 'children': [], 'value': "'|'"},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'generator_expression', 'children': ['236', '240']},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '240', 'type': 'for_in_clause', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '243', 'type': 'for_in_clause', 'children': ['244', '247']},{'id': '244', 'type': 'pattern_list', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '251', 'type': 'argument_list', 'children': []},{'id': '252', 'type': 'if_statement', 'children': ['253', '254', '307', '312']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'pandasMode'},{'id': '254', 'type': 'block', 'children': ['255', '268', '305']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'panDict'},{'id': '258', 'type': 'dictionary', 'children': ['259', '262', '265']},{'id': '259', 'type': 'pair', 'children': ['260', '261']},{'id': '260', 'type': 'string', 'children': [], 'value': "'entry'"},{'id': '261', 'type': 'list', 'children': [], 'value': '[]'},{'id': '262', 'type': 'pair', 'children': ['263', '264']},{'id': '263', 'type': 'string', 'children': [], 'value': "'count'"},{'id': '264', 'type': 'list', 'children': [], 'value': '[]'},{'id': '265', 'type': 'pair', 'children': ['266', '267']},{'id': '266', 'type': 'string', 'children': [], 'value': "'year'"},{'id': '267', 'type': 'list', 'children': [], 'value': '[]'},{'id': '268', 'type': 'for_statement', 'children': ['269', '272', '273']},{'id': '269', 'type': 'pattern_list', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'seriesList'},{'id': '273', 'type': 'block', 'children': ['274', '283', '292']},{'id': '274', 'type': 'expression_statement', 'children': ['275']},{'id': '275', 'type': 'call', 'children': ['276', '281']},{'id': '276', 'type': 'attribute', 'children': ['277', '280']},{'id': '277', 'type': 'subscript', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'panDict'},{'id': '279', 'type': 'string', 'children': [], 'value': "'entry'"},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '281', 'type': 'argument_list', 'children': ['282']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'call', 'children': ['285', '290']},{'id': '285', 'type': 'attribute', 'children': ['286', '289']},{'id': '286', 'type': 'subscript', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'panDict'},{'id': '288', 'type': 'string', 'children': [], 'value': "'year'"},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '292', 'type': 'expression_statement', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '299']},{'id': '294', 'type': 'attribute', 'children': ['295', '298']},{'id': '295', 'type': 'subscript', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'panDict'},{'id': '297', 'type': 'string', 'children': [], 'value': "'count'"},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'subscript', 'children': ['301', '304']},{'id': '301', 'type': 'subscript', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'seriesDict'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'year'},{'id': '305', 'type': 'return_statement', 'children': ['306']},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'panDict'},{'id': '307', 'type': 'elif_clause', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'giveYears'},{'id': '309', 'type': 'block', 'children': ['310']},{'id': '310', 'type': 'return_statement', 'children': ['311']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'seriesList'},{'id': '312', 'type': 'else_clause', 'children': ['313']},{'id': '313', 'type': 'block', 'children': ['314']},{'id': '314', 'type': 'return_statement', 'children': ['315']},{'id': '315', 'type': 'list_comprehension', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '317', 'type': 'for_in_clause', 'children': ['318', '321']},{'id': '318', 'type': 'pattern_list', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'seriesList'} | def timeSeries(self, tag = None, outputFile = None, giveYears = True, greatestFirst = True, limitTo = False, pandasMode = True):
seriesDict = {}
for R in self:
try:
year = R['year']
except KeyError:
continue
if tag is None:
seriesDict[R] = {year : 1}
else:
try:
val = R[tag]
except KeyError:
continue
if not isinstance(val, list):
val = [val]
for entry in val:
if limitTo and entry not in limitTo:
continue
if entry in seriesDict:
try:
seriesDict[entry][year] += 1
except KeyError:
seriesDict[entry][year] = 1
else:
seriesDict[entry] = {year : 1}
seriesList = []
for e, yd in seriesDict.items():
seriesList += [(e, y) for y in yd.keys()]
seriesList = sorted(seriesList, key = lambda x: x[1], reverse = greatestFirst)
if outputFile is not None:
with open(outputFile, 'w') as f:
writer = csv.writer(f, dialect = 'excel')
writer.writerow((str(tag), 'years'))
writer.writerows(((k,'|'.join((str(y) for y in v))) for k,v in seriesDict.items()))
if pandasMode:
panDict = {'entry' : [], 'count' : [], 'year' : []}
for entry, year in seriesList:
panDict['entry'].append(entry)
panDict['year'].append(year)
panDict['count'].append(seriesDict[entry][year])
return panDict
elif giveYears:
return seriesList
else:
return [e for e,c in seriesList] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cooccurrenceCounts'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'keyTag'},{'id': '6', 'type': 'list_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'countedTags'},{'id': '8', 'type': 'block', 'children': ['9', '27', '40', '62', '66', '83', '104', '267']},{'id': '9', 'type': 'if_statement', 'children': ['10', '16']},{'id': '10', 'type': 'not_operator', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'keyTag'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'raise_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'TagError'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'string', 'children': [], 'value': '"\'{}\' is not a string it cannot be used as a tag."'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'keyTag'},{'id': '27', 'type': 'if_statement', 'children': ['28', '34']},{'id': '28', 'type': 'comparison_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': 'countedTags'},{'id': '33', 'type': 'integer', 'children': [], 'value': '1'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'TagError'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'string', 'children': [], 'value': '"You need to provide atleast one tag"'},{'id': '40', 'type': 'for_statement', 'children': ['41', '42', '43']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'countedTags'},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'if_statement', 'children': ['45', '51']},{'id': '45', 'type': 'not_operator', 'children': ['46']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'str'},{'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': 'TagError'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': '"\'{}\' is not a string it cannot be used as a tag."'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'occurenceDict'},{'id': '65', 'type': 'dictionary', 'children': []},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'progArgs'},{'id': '69', 'type': 'tuple', 'children': ['70', '71']},{'id': '70', 'type': 'integer', 'children': [], 'value': '0'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': '"Starting to count the co-occurrences of \'{}\' and\' {}\'"'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'keyTag'},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'string', 'children': [], 'value': '"\',\'"'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'countedTags'},{'id': '83', 'type': 'if_statement', 'children': ['84', '87', '95']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'metaknowledge'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'VERBOSE_MODE'},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'progKwargs'},{'id': '91', 'type': 'dictionary', 'children': ['92']},{'id': '92', 'type': 'pair', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': "'dummy'"},{'id': '94', 'type': 'False', 'children': []},{'id': '95', 'type': 'else_clause', 'children': ['96']},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'progKwargs'},{'id': '100', 'type': 'dictionary', 'children': ['101']},{'id': '101', 'type': 'pair', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': "'dummy'"},{'id': '103', 'type': 'True', 'children': []},{'id': '104', 'type': 'with_statement', 'children': ['105', '117']},{'id': '105', 'type': 'with_clause', 'children': ['106']},{'id': '106', 'type': 'with_item', 'children': ['107']},{'id': '107', 'type': 'as_pattern', 'children': ['108', '115']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_ProgressBar'},{'id': '110', 'type': 'argument_list', 'children': ['111', '113']},{'id': '111', 'type': 'list_splat', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'progArgs'},{'id': '113', 'type': 'dictionary_splat', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'progKwargs'},{'id': '115', 'type': 'as_pattern_target', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'PBar'},{'id': '117', 'type': 'block', 'children': ['118', '249']},{'id': '118', 'type': 'for_statement', 'children': ['119', '122', '126']},{'id': '119', 'type': 'pattern_list', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'block', 'children': ['127', '145', '154', '160', '173', '188']},{'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': 'PBar'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'updateVal'},{'id': '132', 'type': 'argument_list', 'children': ['133', '139']},{'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '/'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'string', 'children': [], 'value': '"Analyzing {}"'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'keyVal'},{'id': '148', 'type': 'call', 'children': ['149', '152']},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'keyTag'},{'id': '154', 'type': 'if_statement', 'children': ['155', '158']},{'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': 'is'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'keyVal'},{'id': '157', 'type': 'None', 'children': []},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'continue_statement', 'children': []},{'id': '160', 'type': 'if_statement', 'children': ['161', '167']},{'id': '161', 'type': 'not_operator', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '164', 'type': 'argument_list', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'keyVal'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'keyVal'},{'id': '171', 'type': 'list', 'children': ['172'], 'value': '[keyVal]'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'keyVal'},{'id': '173', 'type': 'for_statement', 'children': ['174', '175', '176']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'keyVal'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'if_statement', 'children': ['178', '181']},{'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': 'not'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'occurenceDict'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '187']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'occurenceDict'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '187', 'type': 'dictionary', 'children': []},{'id': '188', 'type': 'for_statement', 'children': ['189', '190', '191']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'countedTags'},{'id': '191', 'type': 'block', 'children': ['192', '201', '207', '220']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'tagval'},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '201', 'type': 'if_statement', 'children': ['202', '205']},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': 'is'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'tagval'},{'id': '204', 'type': 'None', 'children': []},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'continue_statement', 'children': []},{'id': '207', 'type': 'if_statement', 'children': ['208', '214']},{'id': '208', 'type': 'not_operator', 'children': ['209']},{'id': '209', 'type': 'call', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '211', 'type': 'argument_list', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'tagval'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '214', 'type': 'block', 'children': ['215']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'tagval'},{'id': '218', 'type': 'list', 'children': ['219'], 'value': '[tagval]'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'tagval'},{'id': '220', 'type': 'for_statement', 'children': ['221', '222', '223']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'tagval'},{'id': '223', 'type': 'block', 'children': ['224']},{'id': '224', 'type': 'for_statement', 'children': ['225', '226', '227']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'keyVal'},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'try_statement', 'children': ['229', '238']},{'id': '229', 'type': 'block', 'children': ['230']},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'augmented_assignment', 'children': ['232', '237'], 'value': '+='},{'id': '232', 'type': 'subscript', 'children': ['233', '236']},{'id': '233', 'type': 'subscript', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'occurenceDict'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '237', 'type': 'integer', 'children': [], 'value': '1'},{'id': '238', 'type': 'except_clause', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '240', 'type': 'block', 'children': ['241']},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '248']},{'id': '243', 'type': 'subscript', 'children': ['244', '247']},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'occurenceDict'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '248', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'PBar'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'finish'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'string', 'children': [], 'value': '"Done extracting the co-occurrences of \'{}\' and \'{}\'"'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '259', 'type': 'argument_list', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'keyTag'},{'id': '261', 'type': 'call', 'children': ['262', '265']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'string', 'children': [], 'value': '"\',\'"'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'countedTags'},{'id': '267', 'type': 'return_statement', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'occurenceDict'} | def cooccurrenceCounts(self, keyTag, *countedTags):
if not isinstance(keyTag, str):
raise TagError("'{}' is not a string it cannot be used as a tag.".format(keyTag))
if len(countedTags) < 1:
TagError("You need to provide atleast one tag")
for tag in countedTags:
if not isinstance(tag, str):
raise TagError("'{}' is not a string it cannot be used as a tag.".format(tag))
occurenceDict = {}
progArgs = (0, "Starting to count the co-occurrences of '{}' and' {}'".format(keyTag, "','".join(countedTags)))
if metaknowledge.VERBOSE_MODE:
progKwargs = {'dummy' : False}
else:
progKwargs = {'dummy' : True}
with _ProgressBar(*progArgs, **progKwargs) as PBar:
for i, R in enumerate(self):
PBar.updateVal(i / len(self), "Analyzing {}".format(R))
keyVal = R.get(keyTag)
if keyVal is None:
continue
if not isinstance(keyVal, list):
keyVal = [keyVal]
for key in keyVal:
if key not in occurenceDict:
occurenceDict[key] = {}
for tag in countedTags:
tagval = R.get(tag)
if tagval is None:
continue
if not isinstance(tagval, list):
tagval = [tagval]
for val in tagval:
for key in keyVal:
try:
occurenceDict[key][val] += 1
except KeyError:
occurenceDict[key][val] = 1
PBar.finish("Done extracting the co-occurrences of '{}' and '{}'".format(keyTag, "','".join(countedTags)))
return occurenceDict |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'getCitations'},{'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': 'field'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'pandasFriendly'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '19', '50', '107', '116']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'retCites'},{'id': '18', 'type': 'list', 'children': [], 'value': '[]'},{'id': '19', 'type': 'if_statement', 'children': ['20', '23']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'if_statement', 'children': ['25', '44']},{'id': '25', 'type': 'boolean_operator', 'children': ['26', '34'], 'value': 'or'},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '30', 'type': 'tuple', 'children': ['31', '32', '33']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '34', 'type': 'not_operator', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '39', 'type': 'attribute', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'abc'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'Container'},{'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': 'values'},{'id': '48', 'type': 'list', 'children': ['49'], 'value': '[values]'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '50', 'type': 'if_statement', 'children': ['51', '54', '95']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'for_statement', 'children': ['56', '57', '64']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '61', 'type': 'argument_list', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '63', 'type': 'list', 'children': [], 'value': '[]'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'try_statement', 'children': ['66', '91']},{'id': '66', 'type': 'block', 'children': ['67', '75']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'targetVal'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '75', 'type': 'if_statement', 'children': ['76', '83']},{'id': '76', 'type': 'boolean_operator', 'children': ['77', '80'], 'value': 'or'},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'is'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '79', 'type': 'None', 'children': []},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'in'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'targetVal'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'retCites'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'cite'},{'id': '91', 'type': 'except_clause', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'pass_statement', 'children': []},{'id': '95', 'type': 'else_clause', 'children': ['96']},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'retCites'},{'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': 'get'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': "'citations'"},{'id': '106', 'type': 'list', 'children': [], 'value': '[]'},{'id': '107', 'type': 'if_statement', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'pandasFriendly'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'return_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': '_pandasPrep'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'retCites'},{'id': '115', 'type': 'False', 'children': []},{'id': '116', 'type': 'return_statement', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'retCites'} | def getCitations(self, field = None, values = None, pandasFriendly = True):
retCites = []
if values is not None:
if isinstance(values, (str, int, float)) or not isinstance(values, collections.abc.Container):
values = [values]
if field is not None:
for cite in self.get('citations', []):
try:
targetVal = getattr(cite, field)
if values is None or targetVal in values:
retCites.append(cite)
except AttributeError:
pass
else:
retCites = self.get('citations', [])
if pandasFriendly:
return _pandasPrep(retCites, False)
return retCites |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'proQuestParser'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'proFile'},{'id': '5', 'type': 'block', 'children': ['6', '10', '16', '20', '24', '301']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'nameDict'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'recSet'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'lineNum'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'try_statement', 'children': ['25', '273']},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'with_statement', 'children': ['27', '40']},{'id': '27', 'type': 'with_clause', 'children': ['28']},{'id': '28', 'type': 'with_item', 'children': ['29']},{'id': '29', 'type': 'as_pattern', 'children': ['30', '38']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'proFile'},{'id': '34', 'type': 'string', 'children': [], 'value': "'r'"},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '37', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '38', 'type': 'as_pattern_target', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'openfile'},{'id': '40', 'type': 'block', 'children': ['41', '51', '67', '146']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '46', 'type': 'argument_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'openfile'},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '50', 'type': 'integer', 'children': [], 'value': '1'},{'id': '51', 'type': 'for_statement', 'children': ['52', '53', '57']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'integer', 'children': [], 'value': '12'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '63']},{'id': '60', 'type': 'pattern_list', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'lineNum'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '67', 'type': 'while_statement', 'children': ['68', '69']},{'id': '68', 'type': 'True', 'children': []},{'id': '69', 'type': 'block', 'children': ['70', '79', '88']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '75']},{'id': '72', 'type': 'pattern_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'lineNum'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'f'},{'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': 'lineNum'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '88', 'type': 'if_statement', 'children': ['89', '92', '110']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': '=='},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '91', 'type': 'string', 'children': [], 'value': "'Bibliography\\n'"},{'id': '92', 'type': 'block', 'children': ['93', '109']},{'id': '93', 'type': 'for_statement', 'children': ['94', '95', '99']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'integer', 'children': [], 'value': '3'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '105']},{'id': '102', 'type': 'pattern_list', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'lineNum'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '109', 'type': 'break_statement', 'children': []},{'id': '110', 'type': 'else_clause', 'children': ['111']},{'id': '111', 'type': 'block', 'children': ['112', '121']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'string', 'children': [], 'value': "'. '"},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '131']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'nameDict'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'subscript', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '130', 'type': 'integer', 'children': [], 'value': '0'},{'id': '131', 'type': 'subscript', 'children': ['132', '142']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'string', 'children': [], 'value': "'. '"},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '139', 'type': 'slice', 'children': ['140', '141']},{'id': '140', 'type': 'integer', 'children': [], 'value': '1'},{'id': '141', 'type': 'colon', 'children': []},{'id': '142', 'type': 'slice', 'children': ['143', '144']},{'id': '143', 'type': 'colon', 'children': []},{'id': '144', 'type': 'unary_operator', 'children': ['145'], 'value': '-'},{'id': '145', 'type': 'integer', 'children': [], 'value': '1'},{'id': '146', 'type': 'while_statement', 'children': ['147', '148']},{'id': '147', 'type': 'True', 'children': []},{'id': '148', 'type': 'block', 'children': ['149', '158']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '154']},{'id': '151', 'type': 'pattern_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'lineNum'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '158', 'type': 'if_statement', 'children': ['159', '162', '164', '256']},{'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': '=='},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '161', 'type': 'string', 'children': [], 'value': "'Bibliography\\n'"},{'id': '162', 'type': 'block', 'children': ['163']},{'id': '163', 'type': 'break_statement', 'children': []},{'id': '164', 'type': 'elif_clause', 'children': ['165', '171']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'string', 'children': [], 'value': "'Document '"},{'id': '171', 'type': 'block', 'children': ['172', '190', '203', '240', '247']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '177', 'type': 'argument_list', 'children': ['178']},{'id': '178', 'type': 'subscript', 'children': ['179', '189']},{'id': '179', 'type': 'call', 'children': ['180', '187']},{'id': '180', 'type': 'attribute', 'children': ['181', '186']},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '183', 'type': 'slice', 'children': ['184', '185']},{'id': '184', 'type': 'integer', 'children': [], 'value': '9'},{'id': '185', 'type': 'colon', 'children': []},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'string', 'children': [], 'value': "' of '"},{'id': '189', 'type': 'integer', 'children': [], 'value': '0'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '193', 'type': 'call', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'ProQuestRecord'},{'id': '195', 'type': 'argument_list', 'children': ['196', '197', '200']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'sFile'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'proFile'},{'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'sLine'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'lineNum'},{'id': '203', 'type': 'if_statement', 'children': ['204', '214']},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '211'], 'value': '!='},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'string', 'children': [], 'value': "'Title'"},{'id': '211', 'type': 'subscript', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'nameDict'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '214', 'type': 'block', 'children': ['215', '238']},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'BadProQuestFile'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'string', 'children': [], 'value': '"The numbering of the titles at the beginning of the file does not match the records inside. Line {} has a record titled \'{}\' with number {}, the name should be \'{}\'."'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227', '234', '235']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'lineNum'},{'id': '227', 'type': 'call', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '231', 'type': 'argument_list', 'children': ['232', '233']},{'id': '232', 'type': 'string', 'children': [], 'value': "'Title'"},{'id': '233', 'type': 'string', 'children': [], 'value': '"TITLE MISSING"'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'nameDict'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '238', 'type': 'raise_statement', 'children': ['239']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'call', 'children': ['242', '245']},{'id': '242', 'type': 'attribute', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'recSet'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'R'},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '252']},{'id': '249', 'type': 'pattern_list', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'lineNum'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '252', 'type': 'call', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '256', 'type': 'else_clause', 'children': ['257']},{'id': '257', 'type': 'block', 'children': ['258', '271']},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '261', 'type': 'call', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'BadProQuestFile'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '268']},{'id': '265', 'type': 'attribute', 'children': ['266', '267']},{'id': '266', 'type': 'string', 'children': [], 'value': '"The file \'{}\' has parts of it that are unparsable starting at line: {}. It is likely that the seperators between the records are incorrect"'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '268', 'type': 'argument_list', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'proFile'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'lineNum'},{'id': '271', 'type': 'raise_statement', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '273', 'type': 'except_clause', 'children': ['274', '281']},{'id': '274', 'type': 'as_pattern', 'children': ['275', '279']},{'id': '275', 'type': 'tuple', 'children': ['276', '277', '278']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'UnicodeDecodeError'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'StopIteration'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '279', 'type': 'as_pattern_target', 'children': ['280']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '281', 'type': 'block', 'children': ['282']},{'id': '282', 'type': 'if_statement', 'children': ['283', '286']},{'id': '283', 'type': 'comparison_operator', 'children': ['284', '285'], 'value': 'is'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '285', 'type': 'None', 'children': []},{'id': '286', 'type': 'block', 'children': ['287']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '290', 'type': 'call', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'BadProQuestFile'},{'id': '292', 'type': 'argument_list', 'children': ['293']},{'id': '293', 'type': 'call', 'children': ['294', '297']},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'string', 'children': [], 'value': '"The file \'{}\' has parts of it that are unparsable starting at line: {}.\\nThe error was: \'{}\'"'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '297', 'type': 'argument_list', 'children': ['298', '299', '300']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'proFile'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'lineNum'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '301', 'type': 'return_statement', 'children': ['302']},{'id': '302', 'type': 'expression_list', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'recSet'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'error'} | def proQuestParser(proFile):
nameDict = {}
recSet = set()
error = None
lineNum = 0
try:
with open(proFile, 'r', encoding = 'utf-8') as openfile:
f = enumerate(openfile, start = 1)
for i in range(12):
lineNum, line = next(f)
while True:
lineNum, line = next(f)
lineNum, line = next(f)
if line == 'Bibliography\n':
for i in range(3):
lineNum, line = next(f)
break
else:
s = line.split('. ')
nameDict[int(s[0])] = '. '.join(s[1:])[:-1]
while True:
lineNum, line = next(f)
if line == 'Bibliography\n':
break
elif line.startswith('Document '):
n = int(line[9:].split(' of ')[0])
R = ProQuestRecord(f, sFile = proFile, sLine = lineNum)
if R.get('Title') != nameDict[n]:
error = BadProQuestFile("The numbering of the titles at the beginning of the file does not match the records inside. Line {} has a record titled '{}' with number {}, the name should be '{}'.".format(lineNum, R.get('Title', "TITLE MISSING"), n, nameDict[n]))
raise StopIteration
recSet.add(R)
lineNum, line = next(f)
else:
error = BadProQuestFile("The file '{}' has parts of it that are unparsable starting at line: {}. It is likely that the seperators between the records are incorrect".format(proFile, lineNum))
raise StopIteration
except (UnicodeDecodeError, StopIteration, ValueError) as e:
if error is None:
error = BadProQuestFile("The file '{}' has parts of it that are unparsable starting at line: {}.\nThe error was: '{}'".format(proFile, lineNum, e))
return recSet, error |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'minus'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'repo_list_a'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'repo_list_b'},{'id': '6', 'type': 'block', 'children': ['7', '15', '27', '33', '60']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'included'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'lambda', 'children': ['14']},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '18']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'repo'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'repo_list_b'},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '26']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'included'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'repo'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '26', 'type': 'True', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'a_minus_b'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'for_statement', 'children': ['34', '35', '36']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'repo'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'repo_list_a'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'if_statement', 'children': ['38', '44']},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'included'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'repo'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '44', 'type': 'block', 'children': ['45', '53']},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '52']},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'included'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'repo'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'full_name'},{'id': '52', 'type': 'True', 'children': []},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'a_minus_b'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'repo'},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'a_minus_b'} | def minus(repo_list_a, repo_list_b):
included = defaultdict(lambda: False)
for repo in repo_list_b:
included[repo.full_name] = True
a_minus_b = list()
for repo in repo_list_a:
if not included[repo.full_name]:
included[repo.full_name] = True
a_minus_b.append(repo)
return a_minus_b |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__clean_and_tokenize'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'doc_list'},{'id': '6', 'type': 'block', 'children': ['7', '29', '35', '42', '50', '58', '122']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'doc_list'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '12', 'type': 'argument_list', 'children': ['13', '28']},{'id': '13', 'type': 'lambda', 'children': ['14', '16']},{'id': '14', 'type': 'lambda_parameters', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'x'},{'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': 'x'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '25'], 'value': '<='},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'GitSuggest'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'MAX_DESC_LEN'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'doc_list'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'cleaned_doc_list'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '34', 'type': 'argument_list', 'children': []},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'tokenizer'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'RegexpTokenizer'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'string', 'children': [], 'value': 'r"[a-zA-Z]+"'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'stopwords'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '48', 'type': 'identifier', 'children': [], 'value': '__get_words_to_ignore'},{'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': 'dict_words'},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '__get_words_to_consider'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'for_statement', 'children': ['59', '60', '61']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'doc_list'},{'id': '61', 'type': 'block', 'children': ['62', '70', '79', '91', '103', '115']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'doc'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '69', 'type': 'argument_list', 'children': []},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'tokenizer'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'tokenize'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '82', 'type': 'list_comprehension', 'children': ['83', '84', '87']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'tok'},{'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'tok'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '87', 'type': 'if_clause', 'children': ['88']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': 'in'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'tok'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'dict_words'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '94', 'type': 'list_comprehension', 'children': ['95', '96', '99']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'tok'},{'id': '96', 'type': 'for_in_clause', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'tok'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '99', 'type': 'if_clause', 'children': ['100']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'not'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'tok'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'stopwords'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '106', 'type': 'list_comprehension', 'children': ['107', '108', '111']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'tok'},{'id': '108', 'type': 'for_in_clause', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'tok'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '111', 'type': 'if_clause', 'children': ['112']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'is'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'tok'},{'id': '114', 'type': 'None', 'children': []},{'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': 'cleaned_doc_list'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'tokens'},{'id': '122', 'type': 'return_statement', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'cleaned_doc_list'} | def __clean_and_tokenize(self, doc_list):
doc_list = filter(
lambda x: x is not None and len(x) <= GitSuggest.MAX_DESC_LEN,
doc_list,
)
cleaned_doc_list = list()
tokenizer = RegexpTokenizer(r"[a-zA-Z]+")
stopwords = self.__get_words_to_ignore()
dict_words = self.__get_words_to_consider()
for doc in doc_list:
lower = doc.lower()
tokens = tokenizer.tokenize(lower)
tokens = [tok for tok in tokens if tok in dict_words]
tokens = [tok for tok in tokens if tok not in stopwords]
tokens = [tok for tok in tokens if tok is not None]
cleaned_doc_list.append(tokens)
return cleaned_doc_list |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '__get_search_results'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '10', 'type': 'block', 'children': ['11', '27', '59', '93', '99', '131', '142', '149', '164', '220']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'order_by_options'},{'id': '14', 'type': 'list', 'children': ['15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26'], 'value': "['search_rank', 'series_id', 'title', 'units', 'frequency',\n 'seasonal_adjustment', 'realtime_start', 'realtime_end', 'last_updated',\n 'observation_start', 'observation_end', 'popularity']"},{'id': '15', 'type': 'string', 'children': [], 'value': "'search_rank'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'series_id'"},{'id': '17', 'type': 'string', 'children': [], 'value': "'title'"},{'id': '18', 'type': 'string', 'children': [], 'value': "'units'"},{'id': '19', 'type': 'string', 'children': [], 'value': "'frequency'"},{'id': '20', 'type': 'string', 'children': [], 'value': "'seasonal_adjustment'"},{'id': '21', 'type': 'string', 'children': [], 'value': "'realtime_start'"},{'id': '22', 'type': 'string', 'children': [], 'value': "'realtime_end'"},{'id': '23', 'type': 'string', 'children': [], 'value': "'last_updated'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'observation_start'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'observation_end'"},{'id': '26', 'type': 'string', 'children': [], 'value': "'popularity'"},{'id': '27', 'type': 'if_statement', 'children': ['28', '31']},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '30', 'type': 'None', 'children': []},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'if_statement', 'children': ['33', '36', '45']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'in'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'order_by_options'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '44'], 'value': '+'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '+'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '43', 'type': 'string', 'children': [], 'value': "'&order_by='"},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '45', 'type': 'else_clause', 'children': ['46']},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'raise_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '%'},{'id': '52', 'type': 'string', 'children': [], 'value': "'%s is not in the valid list of order_by options: %s'"},{'id': '53', 'type': 'tuple', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'order_by_options'},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '62', 'type': 'None', 'children': []},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'if_statement', 'children': ['65', '71', '86']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '70'], 'value': '=='},{'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': 'filter'},{'id': '70', 'type': 'integer', 'children': [], 'value': '2'},{'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': 'url'},{'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '+'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '77', 'type': 'binary_operator', 'children': ['78', '79'], 'value': '%'},{'id': '78', 'type': 'string', 'children': [], 'value': "'&filter_variable=%s&filter_value=%s'"},{'id': '79', 'type': 'tuple', 'children': ['80', '83']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'else_clause', 'children': ['87']},{'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': 'ValueError'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'string', 'children': [], 'value': "'Filter should be a 2 item tuple like (filter_variable, filter_value)'"},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'sort_order_options'},{'id': '96', 'type': 'list', 'children': ['97', '98'], 'value': "['asc', 'desc']"},{'id': '97', 'type': 'string', 'children': [], 'value': "'asc'"},{'id': '98', 'type': 'string', 'children': [], 'value': "'desc'"},{'id': '99', 'type': 'if_statement', 'children': ['100', '103']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'is'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '102', 'type': 'None', 'children': []},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'if_statement', 'children': ['105', '108', '117']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'in'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sort_order_options'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '112', 'type': 'binary_operator', 'children': ['113', '116'], 'value': '+'},{'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '+'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '115', 'type': 'string', 'children': [], 'value': "'&sort_order='"},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '117', 'type': 'else_clause', 'children': ['118']},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'raise_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'binary_operator', 'children': ['124', '125'], 'value': '%'},{'id': '124', 'type': 'string', 'children': [], 'value': "'%s is not in the valid list of sort_order options: %s'"},{'id': '125', 'type': 'tuple', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'sort_order_options'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '136']},{'id': '133', 'type': 'pattern_list', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'num_results_total'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': '__do_series_search'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '142', 'type': 'if_statement', 'children': ['143', '146']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': 'is'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '145', 'type': 'None', 'children': []},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'return_statement', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '149', 'type': 'if_statement', 'children': ['150', '153', '158']},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': '=='},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'max_results_needed'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'num_results_total'},{'id': '158', 'type': 'else_clause', 'children': ['159']},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'max_results_needed'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '164', 'type': 'if_statement', 'children': ['165', '170']},{'id': '165', 'type': 'comparison_operator', 'children': ['166', '167'], 'value': '>'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'max_results_needed'},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'max_results_per_request'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'for_statement', 'children': ['172', '173', '184']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177']},{'id': '176', 'type': 'integer', 'children': [], 'value': '1'},{'id': '177', 'type': 'binary_operator', 'children': ['178', '183'], 'value': '+'},{'id': '178', 'type': 'binary_operator', 'children': ['179', '180'], 'value': '//'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'max_results_needed'},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'max_results_per_request'},{'id': '183', 'type': 'integer', 'children': [], 'value': '1'},{'id': '184', 'type': 'block', 'children': ['185', '193', '211']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '188', 'type': 'binary_operator', 'children': ['189', '190'], 'value': '*'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'max_results_per_request'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '198']},{'id': '195', 'type': 'pattern_list', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'next_data'},{'id': '197', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '201', 'type': 'identifier', 'children': [], 'value': '__do_series_search'},{'id': '202', 'type': 'argument_list', 'children': ['203']},{'id': '203', 'type': 'binary_operator', 'children': ['204', '207'], 'value': '+'},{'id': '204', 'type': 'binary_operator', 'children': ['205', '206'], 'value': '+'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '206', 'type': 'string', 'children': [], 'value': "'&offset='"},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'next_data'},{'id': '220', 'type': 'return_statement', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'head'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'max_results_needed'} | def __get_search_results(self, url, limit, order_by, sort_order, filter):
order_by_options = ['search_rank', 'series_id', 'title', 'units', 'frequency',
'seasonal_adjustment', 'realtime_start', 'realtime_end', 'last_updated',
'observation_start', 'observation_end', 'popularity']
if order_by is not None:
if order_by in order_by_options:
url = url + '&order_by=' + order_by
else:
raise ValueError('%s is not in the valid list of order_by options: %s' % (order_by, str(order_by_options)))
if filter is not None:
if len(filter) == 2:
url = url + '&filter_variable=%s&filter_value=%s' % (filter[0], filter[1])
else:
raise ValueError('Filter should be a 2 item tuple like (filter_variable, filter_value)')
sort_order_options = ['asc', 'desc']
if sort_order is not None:
if sort_order in sort_order_options:
url = url + '&sort_order=' + sort_order
else:
raise ValueError('%s is not in the valid list of sort_order options: %s' % (sort_order, str(sort_order_options)))
data, num_results_total = self.__do_series_search(url)
if data is None:
return data
if limit == 0:
max_results_needed = num_results_total
else:
max_results_needed = limit
if max_results_needed > self.max_results_per_request:
for i in range(1, max_results_needed // self.max_results_per_request + 1):
offset = i * self.max_results_per_request
next_data, _ = self.__do_series_search(url + '&offset=' + str(offset))
data = data.append(next_data)
return data.head(max_results_needed) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '8', 'type': 'integer', 'children': [], 'value': '1000'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '32', '45']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '%'},{'id': '23', 'type': 'string', 'children': [], 'value': '"%s/series/search?search_text=%s&"'},{'id': '24', 'type': 'tuple', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'root_url'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'quote_plus'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '__get_search_results'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42', '43', '44']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'info'} | def search(self, text, limit=1000, order_by=None, sort_order=None, filter=None):
url = "%s/series/search?search_text=%s&" % (self.root_url,
quote_plus(text))
info = self.__get_search_results(url, limit, order_by, sort_order, filter)
return info |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_by_release'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'release_id'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '8', 'type': 'integer', 'children': [], 'value': '0'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '29', '42', '57']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '%'},{'id': '23', 'type': 'string', 'children': [], 'value': '"%s/release/series?release_id=%d"'},{'id': '24', 'type': 'tuple', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'root_url'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'release_id'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '__get_search_results'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39', '40', '41']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '42', 'type': 'if_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'raise_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '+'},{'id': '52', 'type': 'string', 'children': [], 'value': "'No series exists for release id: '"},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'release_id'},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'info'} | def search_by_release(self, release_id, limit=0, order_by=None, sort_order=None, filter=None):
url = "%s/release/series?release_id=%d" % (self.root_url, release_id)
info = self.__get_search_results(url, limit, order_by, sort_order, filter)
if info is None:
raise ValueError('No series exists for release id: ' + str(release_id))
return info |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_by_category'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'category_id'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '8', 'type': 'integer', 'children': [], 'value': '0'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'block', 'children': ['19', '29', '42', '57']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '22', 'type': 'binary_operator', 'children': ['23', '24'], 'value': '%'},{'id': '23', 'type': 'string', 'children': [], 'value': '"%s/category/series?category_id=%d&"'},{'id': '24', 'type': 'tuple', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'root_url'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'category_id'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': '__get_search_results'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39', '40', '41']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort_order'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '42', 'type': 'if_statement', 'children': ['43', '46']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': 'is'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '45', 'type': 'None', 'children': []},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'raise_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '+'},{'id': '52', 'type': 'string', 'children': [], 'value': "'No series exists for category id: '"},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'category_id'},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'info'} | def search_by_category(self, category_id, limit=0, order_by=None, sort_order=None, filter=None):
url = "%s/category/series?category_id=%d&" % (self.root_url,
category_id)
info = self.__get_search_results(url, limit, order_by, sort_order, filter)
if info is None:
raise ValueError('No series exists for category id: ' + str(category_id))
return info |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'format_name'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'subject'},{'id': '5', 'type': 'block', 'children': ['6', '31']},{'id': '6', 'type': 'if_statement', 'children': ['7', '14']},{'id': '7', 'type': 'call', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '9', 'type': 'argument_list', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'subject'},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'Name'},{'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': 'subject'},{'id': '18', 'type': 'list_comprehension', 'children': ['19', '28']},{'id': '19', 'type': 'tuple', 'children': ['20', '25']},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'OID_NAME_MAPPINGS'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'oid'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'subject'},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '%'},{'id': '33', 'type': 'string', 'children': [], 'value': "'/%s'"},{'id': '34', 'type': '()', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'list_comprehension', 'children': ['41', '52']},{'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '%'},{'id': '42', 'type': 'string', 'children': [], 'value': "'%s=%s'"},{'id': '43', 'type': 'tuple', 'children': ['44', '48']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'force_text'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'force_text'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '52', 'type': 'for_in_clause', 'children': ['53', '56']},{'id': '53', 'type': 'pattern_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'subject'} | def format_name(subject):
if isinstance(subject, x509.Name):
subject = [(OID_NAME_MAPPINGS[s.oid], s.value) for s in subject]
return '/%s' % ('/'.join(['%s=%s' % (force_text(k), force_text(v)) for k, v in subject])) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_name'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '5', 'type': 'block', 'children': ['6', '14', '20', '67', '105']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'if_statement', 'children': ['15', '17']},{'id': '15', 'type': 'not_operator', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'try_statement', 'children': ['21', '50']},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '25', 'type': 'list_comprehension', 'children': ['26', '42']},{'id': '26', 'type': 'tuple', 'children': ['27', '36']},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'NAME_CASE_MAPPINGS'},{'id': '29', 'type': 'call', 'children': ['30', '35']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'force_text'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '41', 'type': 'integer', 'children': [], 'value': '2'},{'id': '42', 'type': 'for_in_clause', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'NAME_RE'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '50', 'type': 'except_clause', 'children': ['51', '55']},{'id': '51', 'type': 'as_pattern', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '53', 'type': 'as_pattern_target', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'raise_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '%'},{'id': '61', 'type': 'string', 'children': [], 'value': "'Unknown x509 name field: %s'"},{'id': '62', 'type': 'subscript', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '66', 'type': 'integer', 'children': [], 'value': '0'},{'id': '67', 'type': 'for_statement', 'children': ['68', '71', '76']},{'id': '68', 'type': 'pattern_list', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'oid'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'NAME_OID_MAPPINGS'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'if_statement', 'children': ['78', '97']},{'id': '78', 'type': 'boolean_operator', 'children': ['79', '94'], 'value': 'and'},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '93'], 'value': '>'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '82', 'type': 'generator_expression', 'children': ['83', '84', '87']},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '87', 'type': 'if_clause', 'children': ['88']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '92'], 'value': '=='},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '93', 'type': 'integer', 'children': [], 'value': '1'},{'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'not'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'oid'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'MULTIPLE_OIDS'},{'id': '97', 'type': 'block', 'children': ['98']},{'id': '98', 'type': 'raise_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '%'},{'id': '103', 'type': 'string', 'children': [], 'value': '\'Subject contains multiple "%s" fields\''},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '105', 'type': 'return_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sort_name'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'items'} | def parse_name(name):
name = name.strip()
if not name:
return []
try:
items = [(NAME_CASE_MAPPINGS[t[0].upper()], force_text(t[2])) for t in NAME_RE.findall(name)]
except KeyError as e:
raise ValueError('Unknown x509 name field: %s' % e.args[0])
for key, oid in NAME_OID_MAPPINGS.items():
if sum(1 for t in items if t[0] == key) > 1 and oid not in MULTIPLE_OIDS:
raise ValueError('Subject contains multiple "%s" fields' % key)
return sort_name(items) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_general_name'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '5', 'type': 'block', 'children': ['6', '13', '17', '26', '49', '205']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'force_text'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'GENERAL_NAME_RE'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '26', 'type': 'if_statement', 'children': ['27', '30']},{'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '29', 'type': 'None', 'children': []},{'id': '30', 'type': 'block', 'children': ['31', '41']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '36']},{'id': '33', 'type': 'pattern_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'if_statement', 'children': ['50', '53']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'is'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '52', 'type': 'None', 'children': []},{'id': '53', 'type': 'block', 'children': ['54', '76', '97', '119', '135', '151', '198']},{'id': '54', 'type': 'if_statement', 'children': ['55', '62']},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '59', 'type': 'argument_list', 'children': ['60', '61']},{'id': '60', 'type': 'string', 'children': [], 'value': "'[a-z0-9]{2,}://'"},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'try_statement', 'children': ['64', '72']},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'UniformResourceIdentifier'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '72', 'type': 'except_clause', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'pass_statement', 'children': []},{'id': '76', 'type': 'if_statement', 'children': ['77', '80']},{'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'in'},{'id': '78', 'type': 'string', 'children': [], 'value': "'@'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'try_statement', 'children': ['82', '93']},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'return_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'RFC822Name'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'validate_email'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '93', 'type': 'except_clause', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'pass_statement', 'children': []},{'id': '97', 'type': 'if_statement', 'children': ['98', '108']},{'id': '98', 'type': 'call', 'children': ['99', '106']},{'id': '99', 'type': 'attribute', 'children': ['100', '105']},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '104', 'type': 'argument_list', 'children': []},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'return_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'DirectoryName'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'x509_name'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '119', 'type': 'try_statement', 'children': ['120', '131']},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'IPAddress'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'ip_address'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '131', 'type': 'except_clause', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'pass_statement', 'children': []},{'id': '135', 'type': 'try_statement', 'children': ['136', '147']},{'id': '136', 'type': 'block', 'children': ['137']},{'id': '137', 'type': 'return_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'IPAddress'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'ip_network'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '147', 'type': 'except_clause', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'pass_statement', 'children': []},{'id': '151', 'type': 'if_statement', 'children': ['152', '158', '170', '189']},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'string', 'children': [], 'value': "'*.'"},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'idna'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'subscript', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '167', 'type': 'slice', 'children': ['168', '169']},{'id': '168', 'type': 'integer', 'children': [], 'value': '2'},{'id': '169', 'type': 'colon', 'children': []},{'id': '170', 'type': 'elif_clause', 'children': ['171', '177']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '177', 'type': 'block', 'children': ['178']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'idna'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '186', 'type': 'slice', 'children': ['187', '188']},{'id': '187', 'type': 'integer', 'children': [], 'value': '1'},{'id': '188', 'type': 'colon', 'children': []},{'id': '189', 'type': 'else_clause', 'children': ['190']},{'id': '190', 'type': 'block', 'children': ['191']},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'idna'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '198', 'type': 'return_statement', 'children': ['199']},{'id': '199', 'type': 'call', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'DNSName'},{'id': '203', 'type': 'argument_list', 'children': ['204']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '205', 'type': 'if_statement', 'children': ['206', '209', '217', '232', '274', '291', '412', '427']},{'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': '=='},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '208', 'type': 'string', 'children': [], 'value': "'uri'"},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'return_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'UniformResourceIdentifier'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '217', 'type': 'elif_clause', 'children': ['218', '221']},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': '=='},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '220', 'type': 'string', 'children': [], 'value': "'email'"},{'id': '221', 'type': 'block', 'children': ['222']},{'id': '222', 'type': 'return_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'RFC822Name'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'validate_email'},{'id': '230', 'type': 'argument_list', 'children': ['231']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '232', 'type': 'elif_clause', 'children': ['233', '236']},{'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': '=='},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '235', 'type': 'string', 'children': [], 'value': "'ip'"},{'id': '236', 'type': 'block', 'children': ['237', '253', '269']},{'id': '237', 'type': 'try_statement', 'children': ['238', '249']},{'id': '238', 'type': 'block', 'children': ['239']},{'id': '239', 'type': 'return_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'IPAddress'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'ip_address'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '249', 'type': 'except_clause', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '251', 'type': 'block', 'children': ['252']},{'id': '252', 'type': 'pass_statement', 'children': []},{'id': '253', 'type': 'try_statement', 'children': ['254', '265']},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'return_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'IPAddress'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'call', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'ip_network'},{'id': '263', 'type': 'argument_list', 'children': ['264']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '265', 'type': 'except_clause', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'pass_statement', 'children': []},{'id': '269', 'type': 'raise_statement', 'children': ['270']},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'string', 'children': [], 'value': "'Could not parse IP address.'"},{'id': '274', 'type': 'elif_clause', 'children': ['275', '278']},{'id': '275', 'type': 'comparison_operator', 'children': ['276', '277'], 'value': '=='},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '277', 'type': 'string', 'children': [], 'value': "'rid'"},{'id': '278', 'type': 'block', 'children': ['279']},{'id': '279', 'type': 'return_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'RegisteredID'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'call', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'ObjectIdentifier'},{'id': '289', 'type': 'argument_list', 'children': ['290']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '291', 'type': 'elif_clause', 'children': ['292', '295']},{'id': '292', 'type': 'comparison_operator', 'children': ['293', '294'], 'value': '=='},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '294', 'type': 'string', 'children': [], 'value': "'othername'"},{'id': '295', 'type': 'block', 'children': ['296', '300']},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '299', 'type': 'string', 'children': [], 'value': '"(.*);(.*):(.*)"'},{'id': '300', 'type': 'if_statement', 'children': ['301', '310', '403']},{'id': '301', 'type': 'comparison_operator', 'children': ['302', '309'], 'value': 'is'},{'id': '302', 'type': 'call', 'children': ['303', '306']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '306', 'type': 'argument_list', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '309', 'type': 'None', 'children': []},{'id': '310', 'type': 'block', 'children': ['311', '328', '337', '388', '395']},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'assignment', 'children': ['313', '317']},{'id': '313', 'type': 'pattern_list', 'children': ['314', '315', '316']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'oid'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'asn_typ'},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '317', 'type': 'call', 'children': ['318', '327']},{'id': '318', 'type': 'attribute', 'children': ['319', '326']},{'id': '319', 'type': 'call', 'children': ['320', '323']},{'id': '320', 'type': 'attribute', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '323', 'type': 'argument_list', 'children': ['324', '325']},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'groups'},{'id': '327', 'type': 'argument_list', 'children': []},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'assignment', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'oid'},{'id': '331', 'type': 'call', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'ObjectIdentifier'},{'id': '335', 'type': 'argument_list', 'children': ['336']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'oid'},{'id': '337', 'type': 'if_statement', 'children': ['338', '341', '351', '379']},{'id': '338', 'type': 'comparison_operator', 'children': ['339', '340'], 'value': '=='},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'asn_typ'},{'id': '340', 'type': 'string', 'children': [], 'value': "'UTF8'"},{'id': '341', 'type': 'block', 'children': ['342']},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'assignment', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '345', 'type': 'call', 'children': ['346', '349']},{'id': '346', 'type': 'attribute', 'children': ['347', '348']},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '349', 'type': 'argument_list', 'children': ['350']},{'id': '350', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '351', 'type': 'elif_clause', 'children': ['352', '355']},{'id': '352', 'type': 'comparison_operator', 'children': ['353', '354'], 'value': '=='},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'asn_typ'},{'id': '354', 'type': 'string', 'children': [], 'value': "'OctetString'"},{'id': '355', 'type': 'block', 'children': ['356', '368']},{'id': '356', 'type': 'expression_statement', 'children': ['357']},{'id': '357', 'type': 'assignment', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '359', 'type': 'call', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '361', 'type': 'argument_list', 'children': ['362']},{'id': '362', 'type': 'call', 'children': ['363', '366']},{'id': '363', 'type': 'attribute', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'bytearray'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'fromhex'},{'id': '366', 'type': 'argument_list', 'children': ['367']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '368', 'type': 'expression_statement', 'children': ['369']},{'id': '369', 'type': 'assignment', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '371', 'type': 'call', 'children': ['372', '378']},{'id': '372', 'type': 'attribute', 'children': ['373', '377']},{'id': '373', 'type': 'call', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'OctetString'},{'id': '375', 'type': 'argument_list', 'children': ['376']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '378', 'type': 'argument_list', 'children': []},{'id': '379', 'type': 'else_clause', 'children': ['380']},{'id': '380', 'type': 'block', 'children': ['381']},{'id': '381', 'type': 'raise_statement', 'children': ['382']},{'id': '382', 'type': 'call', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '384', 'type': 'argument_list', 'children': ['385']},{'id': '385', 'type': 'binary_operator', 'children': ['386', '387'], 'value': '%'},{'id': '386', 'type': 'string', 'children': [], 'value': "'Unsupported ASN type in otherName: %s'"},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'asn_typ'},{'id': '388', 'type': 'expression_statement', 'children': ['389']},{'id': '389', 'type': 'assignment', 'children': ['390', '391']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '391', 'type': 'call', 'children': ['392', '393']},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'force_bytes'},{'id': '393', 'type': 'argument_list', 'children': ['394']},{'id': '394', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '395', 'type': 'return_statement', 'children': ['396']},{'id': '396', 'type': 'call', 'children': ['397', '400']},{'id': '397', 'type': 'attribute', 'children': ['398', '399']},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'OtherName'},{'id': '400', 'type': 'argument_list', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'oid'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '403', 'type': 'else_clause', 'children': ['404']},{'id': '404', 'type': 'block', 'children': ['405']},{'id': '405', 'type': 'raise_statement', 'children': ['406']},{'id': '406', 'type': 'call', 'children': ['407', '408']},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '408', 'type': 'argument_list', 'children': ['409']},{'id': '409', 'type': 'binary_operator', 'children': ['410', '411'], 'value': '%'},{'id': '410', 'type': 'string', 'children': [], 'value': "'Incorrect otherName format: %s'"},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '412', 'type': 'elif_clause', 'children': ['413', '416']},{'id': '413', 'type': 'comparison_operator', 'children': ['414', '415'], 'value': '=='},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'typ'},{'id': '415', 'type': 'string', 'children': [], 'value': "'dirname'"},{'id': '416', 'type': 'block', 'children': ['417']},{'id': '417', 'type': 'return_statement', 'children': ['418']},{'id': '418', 'type': 'call', 'children': ['419', '422']},{'id': '419', 'type': 'attribute', 'children': ['420', '421']},{'id': '420', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'DirectoryName'},{'id': '422', 'type': 'argument_list', 'children': ['423']},{'id': '423', 'type': 'call', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'x509_name'},{'id': '425', 'type': 'argument_list', 'children': ['426']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '427', 'type': 'else_clause', 'children': ['428']},{'id': '428', 'type': 'block', 'children': ['429', '476']},{'id': '429', 'type': 'if_statement', 'children': ['430', '436', '448', '467']},{'id': '430', 'type': 'call', 'children': ['431', '434']},{'id': '431', 'type': 'attribute', 'children': ['432', '433']},{'id': '432', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '434', 'type': 'argument_list', 'children': ['435']},{'id': '435', 'type': 'string', 'children': [], 'value': "'*.'"},{'id': '436', 'type': 'block', 'children': ['437']},{'id': '437', 'type': 'expression_statement', 'children': ['438']},{'id': '438', 'type': 'call', 'children': ['439', '442']},{'id': '439', 'type': 'attribute', 'children': ['440', '441']},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'idna'},{'id': '441', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '442', 'type': 'argument_list', 'children': ['443']},{'id': '443', 'type': 'subscript', 'children': ['444', '445']},{'id': '444', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '445', 'type': 'slice', 'children': ['446', '447']},{'id': '446', 'type': 'integer', 'children': [], 'value': '2'},{'id': '447', 'type': 'colon', 'children': []},{'id': '448', 'type': 'elif_clause', 'children': ['449', '455']},{'id': '449', 'type': 'call', 'children': ['450', '453']},{'id': '450', 'type': 'attribute', 'children': ['451', '452']},{'id': '451', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '452', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '453', 'type': 'argument_list', 'children': ['454']},{'id': '454', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '455', 'type': 'block', 'children': ['456']},{'id': '456', 'type': 'expression_statement', 'children': ['457']},{'id': '457', 'type': 'call', 'children': ['458', '461']},{'id': '458', 'type': 'attribute', 'children': ['459', '460']},{'id': '459', 'type': 'identifier', 'children': [], 'value': 'idna'},{'id': '460', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '461', 'type': 'argument_list', 'children': ['462']},{'id': '462', 'type': 'subscript', 'children': ['463', '464']},{'id': '463', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '464', 'type': 'slice', 'children': ['465', '466']},{'id': '465', 'type': 'integer', 'children': [], 'value': '1'},{'id': '466', 'type': 'colon', 'children': []},{'id': '467', 'type': 'else_clause', 'children': ['468']},{'id': '468', 'type': 'block', 'children': ['469']},{'id': '469', 'type': 'expression_statement', 'children': ['470']},{'id': '470', 'type': 'call', 'children': ['471', '474']},{'id': '471', 'type': 'attribute', 'children': ['472', '473']},{'id': '472', 'type': 'identifier', 'children': [], 'value': 'idna'},{'id': '473', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '474', 'type': 'argument_list', 'children': ['475']},{'id': '475', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '476', 'type': 'return_statement', 'children': ['477']},{'id': '477', 'type': 'call', 'children': ['478', '481']},{'id': '478', 'type': 'attribute', 'children': ['479', '480']},{'id': '479', 'type': 'identifier', 'children': [], 'value': 'x509'},{'id': '480', 'type': 'identifier', 'children': [], 'value': 'DNSName'},{'id': '481', 'type': 'argument_list', 'children': ['482']},{'id': '482', 'type': 'identifier', 'children': [], 'value': 'name'} | def parse_general_name(name):
name = force_text(name)
typ = None
match = GENERAL_NAME_RE.match(name)
if match is not None:
typ, name = match.groups()
typ = typ.lower()
if typ is None:
if re.match('[a-z0-9]{2,}://', name):
try:
return x509.UniformResourceIdentifier(name)
except Exception:
pass
if '@' in name:
try:
return x509.RFC822Name(validate_email(name))
except Exception:
pass
if name.strip().startswith('/'):
return x509.DirectoryName(x509_name(name))
try:
return x509.IPAddress(ip_address(name))
except ValueError:
pass
try:
return x509.IPAddress(ip_network(name))
except ValueError:
pass
if name.startswith('*.'):
idna.encode(name[2:])
elif name.startswith('.'):
idna.encode(name[1:])
else:
idna.encode(name)
return x509.DNSName(name)
if typ == 'uri':
return x509.UniformResourceIdentifier(name)
elif typ == 'email':
return x509.RFC822Name(validate_email(name))
elif typ == 'ip':
try:
return x509.IPAddress(ip_address(name))
except ValueError:
pass
try:
return x509.IPAddress(ip_network(name))
except ValueError:
pass
raise ValueError('Could not parse IP address.')
elif typ == 'rid':
return x509.RegisteredID(x509.ObjectIdentifier(name))
elif typ == 'othername':
regex = "(.*);(.*):(.*)"
if re.match(regex, name) is not None:
oid, asn_typ, val = re.match(regex, name).groups()
oid = x509.ObjectIdentifier(oid)
if asn_typ == 'UTF8':
val = val.encode('utf-8')
elif asn_typ == 'OctetString':
val = bytes(bytearray.fromhex(val))
val = OctetString(val).dump()
else:
raise ValueError('Unsupported ASN type in otherName: %s' % asn_typ)
val = force_bytes(val)
return x509.OtherName(oid, val)
else:
raise ValueError('Incorrect otherName format: %s' % name)
elif typ == 'dirname':
return x509.DirectoryName(x509_name(name))
else:
if name.startswith('*.'):
idna.encode(name[2:])
elif name.startswith('.'):
idna.encode(name[1:])
else:
idna.encode(name)
return x509.DNSName(name) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'render'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '20', '35', '59', '75', '88', '94', '132', '147', '181', '191', '200']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': '"pretty"'},{'id': '19', 'type': 'False', 'children': []},{'id': '20', 'type': 'if_statement', 'children': ['21', '28']},{'id': '21', 'type': 'boolean_operator', 'children': ['22', '23'], 'value': 'and'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '27'], 'value': '!='},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_stable'},{'id': '27', 'type': 'string', 'children': [], 'value': '"pretty"'},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_stable'},{'id': '34', 'type': 'False', 'children': []},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '38', 'type': 'block', 'children': ['39', '45']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_stable'},{'id': '44', 'type': 'False', 'children': []},{'id': '45', 'type': 'if_statement', 'children': ['46', '51']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'inject'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '59', 'type': 'if_statement', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '61', 'type': 'block', 'children': ['62', '68']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_stable'},{'id': '67', 'type': 'False', 'children': []},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'inject'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '75', 'type': 'if_statement', 'children': ['76', '83']},{'id': '76', 'type': 'boolean_operator', 'children': ['77', '80'], 'value': 'and'},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '79', 'type': 'identifier', 'children': [], 'value': '_stable'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': '_render'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'return_statement', 'children': ['85']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': '_render'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'pretty_pre'},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'pretty_inner'},{'id': '93', 'type': 'string', 'children': [], 'value': '""'},{'id': '94', 'type': 'if_statement', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '96', 'type': 'block', 'children': ['97', '111']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'pretty_pre'},{'id': '100', 'type': 'conditional_expression', 'children': ['101', '109', '110'], 'value': 'if'},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '+'},{'id': '102', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '103', 'type': '()', 'children': ['104']},{'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '*'},{'id': '105', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '108', 'type': 'identifier', 'children': [], 'value': '_depth'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '110', 'type': 'string', 'children': [], 'value': '""'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'pretty_inner'},{'id': '114', 'type': 'conditional_expression', 'children': ['115', '123', '131'], 'value': 'if'},{'id': '115', 'type': 'binary_operator', 'children': ['116', '117'], 'value': '+'},{'id': '116', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '117', 'type': '()', 'children': ['118']},{'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '*'},{'id': '119', 'type': 'string', 'children': [], 'value': '"\\t"'},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '122', 'type': 'identifier', 'children': [], 'value': '_depth'},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '130'], 'value': '>'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'childs'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'string', 'children': [], 'value': '""'},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'inner'},{'id': '135', 'type': 'conditional_expression', 'children': ['136', '142', '146'], 'value': 'if'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'render_childs'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '142', 'type': 'not_operator', 'children': ['143']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '145', 'type': 'identifier', 'children': [], 'value': '_void'},{'id': '146', 'type': 'string', 'children': [], 'value': '""'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'tag_data'},{'id': '150', 'type': 'subscript', 'children': ['151', '170']},{'id': '151', 'type': 'tuple', 'children': ['152', '153', '158', '163', '164', '165']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'pretty_pre'},{'id': '153', 'type': 'call', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': '_get__tag'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'render_attrs'},{'id': '162', 'type': 'argument_list', 'children': []},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'inner'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'pretty_inner'},{'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__tag'},{'id': '169', 'type': 'argument_list', 'children': []},{'id': '170', 'type': 'slice', 'children': ['171', '172']},{'id': '171', 'type': 'colon', 'children': []},{'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '-'},{'id': '173', 'type': 'integer', 'children': [], 'value': '6'},{'id': '174', 'type': 'subscript', 'children': ['175', '178']},{'id': '175', 'type': 'list', 'children': ['176', '177'], 'value': '[0, 3]'},{'id': '176', 'type': 'integer', 'children': [], 'value': '0'},{'id': '177', 'type': 'integer', 'children': [], 'value': '3'},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': '_void'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '186']},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': '_render'},{'id': '186', 'type': 'binary_operator', 'children': ['187', '190'], 'value': '%'},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': '_template'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'tag_data'},{'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': 'self'},{'id': '195', 'type': 'identifier', 'children': [], 'value': '_stable'},{'id': '196', 'type': 'conditional_expression', 'children': ['197', '198', '199'], 'value': 'if'},{'id': '197', 'type': 'string', 'children': [], 'value': '"pretty"'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'pretty'},{'id': '199', 'type': 'True', 'children': []},{'id': '200', 'type': 'return_statement', 'children': ['201']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '203', 'type': 'identifier', 'children': [], 'value': '_render'} | def render(self, *args, **kwargs):
pretty = kwargs.pop("pretty", False)
if pretty and self._stable != "pretty":
self._stable = False
for arg in args:
self._stable = False
if isinstance(arg, dict):
self.inject(arg)
if kwargs:
self._stable = False
self.inject(kwargs)
if self._stable and self._render:
return self._render
pretty_pre = pretty_inner = ""
if pretty:
pretty_pre = "\n" + ("\t" * self._depth) if pretty else ""
pretty_inner = "\n" + ("\t" * self._depth) if len(self.childs) > 1 else ""
inner = self.render_childs(pretty) if not self._void else ""
tag_data = (
pretty_pre,
self._get__tag(),
self.render_attrs(),
inner,
pretty_inner,
self._get__tag()
)[: 6 - [0, 3][self._void]]
self._render = self._template % tag_data
self._stable = "pretty" if pretty else True
return self._render |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_insert'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dom_group'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'prepend'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '27', '50']},{'id': '16', 'type': 'if_statement', 'children': ['17', '22']},{'id': '17', 'type': 'boolean_operator', 'children': ['18', '19'], 'value': 'and'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': '<'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '21', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'idx'},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'if_statement', 'children': ['28', '29', '34']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'prepend'},{'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': 'idx'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0'},{'id': '34', 'type': 'else_clause', 'children': ['35']},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '39', 'type': 'conditional_expression', 'children': ['40', '41', '44'], 'value': 'if'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'childs'},{'id': '50', 'type': 'if_statement', 'children': ['51', '54']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dom_group'},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'block', 'children': ['55', '76']},{'id': '55', 'type': 'if_statement', 'children': ['56', '70']},{'id': '56', 'type': 'boolean_operator', 'children': ['57', '63'], 'value': 'or'},{'id': '57', 'type': 'not_operator', 'children': ['58']},{'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': 'dom_group'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'Iterable'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'dom_group'},{'id': '67', 'type': 'tuple', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'DOMElement'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'str'},{'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': 'dom_group'},{'id': '74', 'type': 'list', 'children': ['75'], 'value': '[dom_group]'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'dom_group'},{'id': '76', 'type': 'for_statement', 'children': ['77', '80', '84']},{'id': '77', 'type': 'pattern_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'i_group'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'dom_group'},{'id': '84', 'type': 'block', 'children': ['85']},{'id': '85', 'type': 'if_statement', 'children': ['86', '89']},{'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'is'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '88', 'type': 'None', 'children': []},{'id': '89', 'type': 'block', 'children': ['90', '102', '117']},{'id': '90', 'type': 'expression_statement', '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': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'childs'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '97', 'type': 'argument_list', 'children': ['98', '101']},{'id': '98', 'type': 'binary_operator', 'children': ['99', '100'], 'value': '+'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'i_group'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '102', 'type': 'if_statement', 'children': ['103', '110']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '105', 'type': 'argument_list', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '108', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'DOMElement'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '117', 'type': 'if_statement', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '119', 'type': 'block', 'children': ['120']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '123', 'type': 'argument_list', 'children': ['124', '125', '126']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'elem'} | def _insert(self, dom_group, idx=None, prepend=False, name=None):
if idx and idx < 0:
idx = 0
if prepend:
idx = 0
else:
idx = idx if idx is not None else len(self.childs)
if dom_group is not None:
if not isinstance(dom_group, Iterable) or isinstance(
dom_group, (DOMElement, str)
):
dom_group = [dom_group]
for i_group, elem in enumerate(dom_group):
if elem is not None:
self.childs.insert(idx + i_group, elem)
if issubclass(elem.__class__, DOMElement):
elem.parent = self
if name:
setattr(self, name, elem) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_label'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'required'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'value_regex'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'target_labels'},{'id': '8', 'type': 'block', 'children': ['9', '29']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'present'},{'id': '12', 'type': 'boolean_operator', 'children': ['13', '16'], 'value': 'and'},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'target_labels'},{'id': '15', 'type': 'None', 'children': []},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '24']},{'id': '18', 'type': 'attribute', 'children': ['19', '23']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'isdisjoint'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'target_labels'},{'id': '29', 'type': 'if_statement', 'children': ['30', '31', '90']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'present'},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'if_statement', 'children': ['33', '37', '40', '86']},{'id': '33', 'type': 'boolean_operator', 'children': ['34', '35'], 'value': 'and'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'required'},{'id': '35', 'type': 'not_operator', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'value_regex'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'True', 'children': []},{'id': '40', 'type': 'elif_clause', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'value_regex'},{'id': '42', 'type': 'block', 'children': ['43', '52', '64', '84']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'value_regex'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'present_labels'},{'id': '55', 'type': 'binary_operator', 'children': ['56', '60'], 'value': '&'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'target_labels'},{'id': '64', 'type': 'for_statement', 'children': ['65', '66', '67']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'present_labels'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'if_statement', 'children': ['69', '81']},{'id': '69', 'type': 'not_operator', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'bool'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'search'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'target_labels'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'l'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'return_statement', 'children': ['83']},{'id': '83', 'type': 'False', 'children': []},{'id': '84', 'type': 'return_statement', 'children': ['85']},{'id': '85', 'type': 'True', 'children': []},{'id': '86', 'type': 'else_clause', 'children': ['87']},{'id': '87', 'type': 'block', 'children': ['88']},{'id': '88', 'type': 'return_statement', 'children': ['89']},{'id': '89', 'type': 'False', 'children': []},{'id': '90', 'type': 'else_clause', 'children': ['91']},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'return_statement', 'children': ['93']},{'id': '93', 'type': 'not_operator', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'required'} | def check_label(labels, required, value_regex, target_labels):
present = target_labels is not None and not set(labels).isdisjoint(set(target_labels))
if present:
if required and not value_regex:
return True
elif value_regex:
pattern = re.compile(value_regex)
present_labels = set(labels) & set(target_labels)
for l in present_labels:
if not bool(pattern.search(target_labels[l])):
return False
return True
else:
return False
else:
return not required |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'receive_fmf_metadata'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'object_list'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '14', '21', '30', '59', '64', '121']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '13', 'type': 'dictionary', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'fmf_tree'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ExtendedTree'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28', '29']},{'id': '27', 'type': 'string', 'children': [], 'value': '"get FMF metadata for test (path:%s name=%s)"'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '33', 'type': 'list_comprehension', 'children': ['34', '35', '42']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '35', 'type': 'for_in_clause', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'fmf_tree'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'climb'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'if_clause', 'children': ['43']},{'id': '43', 'type': 'boolean_operator', 'children': ['44', '54'], 'value': 'and'},{'id': '44', 'type': 'call', 'children': ['45', '50']},{'id': '45', 'type': 'attribute', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '+'},{'id': '52', 'type': 'string', 'children': [], 'value': '"/"'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'not'},{'id': '55', 'type': 'string', 'children': [], 'value': '"@"'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '59', 'type': 'if_statement', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'object_list'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '64', 'type': 'if_statement', 'children': ['65', '71', '78', '107']},{'id': '65', 'type': 'comparison_operator', 'children': ['66', '70'], 'value': '=='},{'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': 'items'},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'output'},{'id': '75', 'type': 'subscript', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '77', 'type': 'integer', 'children': [], 'value': '0'},{'id': '78', 'type': 'elif_clause', 'children': ['79', '85']},{'id': '79', 'type': 'comparison_operator', 'children': ['80', '84'], 'value': '>'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'Exception'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'string', 'children': [], 'value': '"There is more FMF test metadata for item by name:{}({}) {}"'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96', '100']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '100', 'type': 'list_comprehension', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '104', 'type': 'for_in_clause', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '107', 'type': 'elif_clause', 'children': ['108', '110']},{'id': '108', 'type': 'not_operator', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'raise_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'string', 'children': [], 'value': '"Unable to get FMF metadata for: {}"'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'output'} | def receive_fmf_metadata(name, path, object_list=False):
output = {}
fmf_tree = ExtendedTree(path)
logger.debug("get FMF metadata for test (path:%s name=%s)", path, name)
items = [x for x in fmf_tree.climb() if x.name.endswith("/" + name) and "@" not in x.name]
if object_list:
return items
if len(items) == 1:
output = items[0]
elif len(items) > 1:
raise Exception("There is more FMF test metadata for item by name:{}({}) {}".format(
name, len(items), [x.name for x in items]))
elif not items:
raise Exception("Unable to get FMF metadata for: {}".format(name))
return output |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'prune_overridden'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ansi_string'},{'id': '5', 'type': 'block', 'children': ['6', '27', '138']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'multi_seqs'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '11', 'type': 'generator_expression', 'children': ['12', '13', '21']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '13', 'type': 'for_in_clause', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'RE_ANSI'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'ansi_string'},{'id': '21', 'type': 'if_clause', 'children': ['22']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'in'},{'id': '23', 'type': 'string', 'children': [], 'value': "';'"},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '26', 'type': 'integer', 'children': [], 'value': '1'},{'id': '27', 'type': 'for_statement', 'children': ['28', '31', '32']},{'id': '28', 'type': 'pattern_list', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'multi_seqs'},{'id': '32', 'type': 'block', 'children': ['33', '48', '69', '104', '119']},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'r_codes'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'string', 'children': [], 'value': "';'"},{'id': '48', 'type': 'try_statement', 'children': ['49', '65']},{'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': 'r_codes'},{'id': '53', 'type': 'subscript', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'r_codes'},{'id': '55', 'type': 'slice', 'children': ['56', '57']},{'id': '56', 'type': 'colon', 'children': []},{'id': '57', 'type': 'binary_operator', 'children': ['58', '64'], 'value': '+'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'r_codes'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'string', 'children': [], 'value': "'0'"},{'id': '64', 'type': 'integer', 'children': [], 'value': '1'},{'id': '65', 'type': 'except_clause', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'pass_statement', 'children': []},{'id': '69', 'type': 'for_statement', 'children': ['70', '71', '72']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'CODE_GROUPS'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'for_statement', 'children': ['74', '75', '96']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'subscript', 'children': ['79', '93']},{'id': '79', 'type': 'list_comprehension', 'children': ['80', '81', '89']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '81', 'type': 'for_in_clause', 'children': ['82', '85']},{'id': '82', 'type': 'pattern_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'r_codes'},{'id': '89', 'type': 'if_clause', 'children': ['90']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'in'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '93', 'type': 'slice', 'children': ['94', '95']},{'id': '94', 'type': 'integer', 'children': [], 'value': '1'},{'id': '95', 'type': 'colon', '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': 'r_codes'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'reduced_codes'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'string', 'children': [], 'value': "';'"},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '114', 'type': 'argument_list', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'r_codes'},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '119', 'type': 'if_statement', 'children': ['120', '123']},{'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '!='},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'reduced_codes'},{'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': 'ansi_string'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'ansi_string'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'escape'},{'id': '133', 'type': 'binary_operator', 'children': ['134', '137'], 'value': '+'},{'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '+'},{'id': '135', 'type': 'string', 'children': [], 'value': "'\\033['"},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'reduced_codes'},{'id': '137', 'type': 'string', 'children': [], 'value': "'m'"},{'id': '138', 'type': 'return_statement', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ansi_string'} | def prune_overridden(ansi_string):
multi_seqs = set(p for p in RE_ANSI.findall(ansi_string) if ';' in p[1])
for escape, codes in multi_seqs:
r_codes = list(reversed(codes.split(';')))
try:
r_codes = r_codes[:r_codes.index('0') + 1]
except ValueError:
pass
for group in CODE_GROUPS:
for pos in reversed([i for i, n in enumerate(r_codes) if n in group][1:]):
r_codes.pop(pos)
reduced_codes = ';'.join(sorted(r_codes, key=int))
if codes != reduced_codes:
ansi_string = ansi_string.replace(escape, '\033[' + reduced_codes + 'm')
return ansi_string |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_input'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tagged_string'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'disable_colors'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'keep_tags'},{'id': '7', 'type': 'block', 'children': ['8', '15', '24', '67', '77', '84', '107', '114', '118', '124', '172', '181']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'ANSICodeMapping'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'tagged_string'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'output_colors'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'tagged_string'},{'id': '22', 'type': 'string', 'children': [], 'value': "'value_colors'"},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'tagged_string'},{'id': '24', 'type': 'if_statement', 'children': ['25', '27']},{'id': '25', 'type': 'not_operator', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'keep_tags'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'for_statement', 'children': ['29', '32', '56']},{'id': '29', 'type': 'pattern_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'replacement'},{'id': '32', 'type': 'generator_expression', 'children': ['33', '47']},{'id': '33', 'type': 'tuple', 'children': ['34', '39']},{'id': '34', 'type': 'binary_operator', 'children': ['35', '38'], 'value': '+'},{'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '+'},{'id': '36', 'type': 'string', 'children': [], 'value': "'{'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '38', 'type': 'string', 'children': [], 'value': "'}'"},{'id': '39', 'type': 'conditional_expression', 'children': ['40', '41', '44'], 'value': 'if'},{'id': '40', 'type': 'string', 'children': [], 'value': "''"},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '43', 'type': 'None', 'children': []},{'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '%'},{'id': '45', 'type': 'string', 'children': [], 'value': "'\\033[%dm'"},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'v'},{'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', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'output_colors'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'output_colors'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'replacement'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'output_no_colors'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'RE_ANSI'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': "''"},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'output_colors'},{'id': '77', 'type': 'if_statement', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'disable_colors'},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'return_statement', 'children': ['81']},{'id': '81', 'type': 'expression_list', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'output_no_colors'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'output_no_colors'},{'id': '84', 'type': 'while_statement', 'children': ['85', '86']},{'id': '85', 'type': 'True', 'children': []},{'id': '86', 'type': 'block', 'children': ['87', '97', '103']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'simplified'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'RE_COMBINE'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sub'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'string', 'children': [], 'value': "r'\\033[\\1;\\2m'"},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'output_colors'},{'id': '97', 'type': 'if_statement', 'children': ['98', '101']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': '=='},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'simplified'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'output_colors'},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'break_statement', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'output_colors'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'simplified'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'output_colors'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'prune_overridden'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'output_colors'},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'previous_escape'},{'id': '117', 'type': 'None', 'children': []},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'segments'},{'id': '121', 'type': 'call', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'for_statement', 'children': ['125', '126', '138']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '126', 'type': 'generator_expression', 'children': ['127', '128', '136']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'RE_SPLIT'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'output_colors'},{'id': '136', 'type': 'if_clause', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '138', 'type': 'block', 'children': ['139']},{'id': '139', 'type': 'if_statement', 'children': ['140', '146', '163']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'RE_SPLIT'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'if_statement', 'children': ['148', '151']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': '!='},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'previous_escape'},{'id': '151', 'type': 'block', 'children': ['152', '159']},{'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': 'segments'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'previous_escape'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '163', 'type': 'else_clause', 'children': ['164']},{'id': '164', 'type': 'block', 'children': ['165']},{'id': '165', 'type': 'expression_statement', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'segments'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'output_colors'},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'string', 'children': [], 'value': "''"},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'segments'},{'id': '181', 'type': 'return_statement', 'children': ['182']},{'id': '182', 'type': 'expression_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'output_colors'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'output_no_colors'} | def parse_input(tagged_string, disable_colors, keep_tags):
codes = ANSICodeMapping(tagged_string)
output_colors = getattr(tagged_string, 'value_colors', tagged_string)
if not keep_tags:
for tag, replacement in (('{' + k + '}', '' if v is None else '\033[%dm' % v) for k, v in codes.items()):
output_colors = output_colors.replace(tag, replacement)
output_no_colors = RE_ANSI.sub('', output_colors)
if disable_colors:
return output_no_colors, output_no_colors
while True:
simplified = RE_COMBINE.sub(r'\033[\1;\2m', output_colors)
if simplified == output_colors:
break
output_colors = simplified
output_colors = prune_overridden(output_colors)
previous_escape = None
segments = list()
for item in (i for i in RE_SPLIT.split(output_colors) if i):
if RE_SPLIT.match(item):
if item != previous_escape:
segments.append(item)
previous_escape = item
else:
segments.append(item)
output_colors = ''.join(segments)
return output_colors, output_no_colors |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'memoize'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '5', 'type': 'block', 'children': ['6', '18', '24', '30', '175', '181']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '9', 'type': 'assignment', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_get'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_popitem'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'popitem'},{'id': '30', 'type': 'decorated_definition', 'children': ['31', '38']},{'id': '31', 'type': 'decorator', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'wraps'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '38', 'type': 'function_definition', 'children': ['39', '40', '47']},{'id': '39', 'type': 'function_name', 'children': [], 'value': 'memoizer'},{'id': '40', 'type': 'parameters', 'children': ['41', '42', '43', '45']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '43', 'type': 'list_splat_pattern', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '45', 'type': 'dictionary_splat_pattern', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '47', 'type': 'block', 'children': ['48', '70', '106', '113', '120']},{'id': '48', 'type': 'if_statement', 'children': ['49', '59']},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '52'], 'value': 'or'},{'id': '50', 'type': 'not_operator', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': '_WITH_MEMOIZATION'},{'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': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'Quantity'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65', '66', '68']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '66', 'type': 'list_splat', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '68', 'type': 'dictionary_splat', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'unique_id'},{'id': '73', 'type': 'binary_operator', 'children': ['74', '92'], 'value': '+'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '76', 'type': 'generator_expression', 'children': ['77', '83']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'yy'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '83', 'type': 'for_in_clause', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'yy'},{'id': '85', 'type': 'call', 'children': ['86', '91']},{'id': '86', 'type': 'attribute', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '91', 'type': 'argument_list', 'children': []},{'id': '92', 'type': 'tuple', 'children': ['93', '96', '101']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '100', 'type': 'argument_list', 'children': []},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'hash'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'unique_id'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': '_get'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '120', 'type': 'if_statement', 'children': ['121', '124', '127']},{'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'is'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '123', 'type': 'None', 'children': []},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'return_statement', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '127', 'type': 'else_clause', 'children': ['128']},{'id': '128', 'type': 'block', 'children': ['129', '141', '147', '173']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '134', 'type': 'argument_list', 'children': ['135', '136', '137', '139']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'instance'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '137', 'type': 'list_splat', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '139', 'type': 'dictionary_splat', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '146']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '147', 'type': 'if_statement', 'children': ['148', '154']},{'id': '148', 'type': 'comparison_operator', 'children': ['149', '153'], 'value': '>'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'cache'},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_CACHE_SIZE'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'list_comprehension', 'children': ['157', '161']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': '_popitem'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'False', 'children': []},{'id': '161', 'type': 'for_in_clause', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'call', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '168', 'type': 'argument_list', 'children': ['169', '172']},{'id': '169', 'type': 'binary_operator', 'children': ['170', '171'], 'value': '//'},{'id': '170', 'type': 'identifier', 'children': [], 'value': '_CACHE_SIZE'},{'id': '171', 'type': 'integer', 'children': [], 'value': '2'},{'id': '172', 'type': 'integer', 'children': [], 'value': '1'},{'id': '173', 'type': 'return_statement', 'children': ['174']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'memoizer'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'input_object'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '181', 'type': 'return_statement', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'memoizer'} | def memoize(method):
cache = method.cache = collections.OrderedDict()
_get = cache.get
_popitem = cache.popitem
@functools.wraps(method)
def memoizer(instance, x, *args, **kwargs):
if not _WITH_MEMOIZATION or isinstance(x, u.Quantity):
return method(instance, x, *args, **kwargs)
unique_id = tuple(float(yy.value) for yy in instance.parameters.values()) + (x.size, x.min(), x.max())
key = hash(unique_id)
result = _get(key)
if result is not None:
return result
else:
result = method(instance, x, *args, **kwargs)
cache[key] = result
if len(cache) > _CACHE_SIZE:
[_popitem(False) for i in range(max(_CACHE_SIZE // 2, 1))]
return result
memoizer.input_object = method
return memoizer |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_set_value'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '6', 'type': 'block', 'children': ['7', '36', '65', '99', '123']},{'id': '7', 'type': 'if_statement', 'children': ['8', '19']},{'id': '8', 'type': 'boolean_operator', 'children': ['9', '14'], 'value': 'and'},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '13'], 'value': 'is'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'min_value'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '<'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'min_value'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'raise_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'SettingOutOfBounds'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': '"Trying to set parameter {0} = {1}, which is less than the minimum allowed {2}"'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '28', 'type': 'argument_list', 'children': ['29', '32', '33']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'min_value'},{'id': '36', 'type': 'if_statement', 'children': ['37', '48']},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '43'], 'value': 'and'},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '42'], 'value': 'is'},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'max_value'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': '>'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'max_value'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'raise_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'SettingOutOfBounds'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': '"Trying to set parameter {0} = {1}, which is more than the maximum allowed {2}"'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '57', 'type': 'argument_list', 'children': ['58', '61', '62']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'max_value'},{'id': '65', 'type': 'if_statement', 'children': ['66', '71']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'has_auxiliary_variable'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'with_statement', 'children': ['73', '80']},{'id': '73', 'type': 'with_clause', 'children': ['74']},{'id': '74', 'type': 'with_item', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'warnings'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'catch_warnings'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'block', 'children': ['81', '89']},{'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': 'warnings'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'simplefilter'},{'id': '86', 'type': 'argument_list', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': '"always"'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'RuntimeWarning'},{'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': 'warnings'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '94', 'type': 'argument_list', 'children': ['95', '98']},{'id': '95', 'type': 'concatenated_string', 'children': ['96', '97']},{'id': '96', 'type': 'string', 'children': [], 'value': '"You are trying to assign to a parameter which is either linked or "'},{'id': '97', 'type': 'string', 'children': [], 'value': '"has auxiliary variables. The assignment has no effect."'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'RuntimeWarning'},{'id': '99', 'type': 'if_statement', 'children': ['100', '105', '110']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '104'], 'value': 'is'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '103', 'type': 'identifier', 'children': [], 'value': '_transformation'},{'id': '104', 'type': 'None', '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': 'new_internal_value'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'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': 'new_internal_value'},{'id': '115', 'type': 'call', 'children': ['116', '121']},{'id': '116', 'type': 'attribute', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '119', 'type': 'identifier', 'children': [], 'value': '_transformation'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'forward'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'new_value'},{'id': '123', 'type': 'if_statement', 'children': ['124', '129']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': '!='},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'new_internal_value'},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '128', 'type': 'identifier', 'children': [], 'value': '_internal_value'},{'id': '129', 'type': 'block', 'children': ['130', '136']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '134', 'type': 'identifier', 'children': [], 'value': '_internal_value'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'new_internal_value'},{'id': '136', 'type': 'for_statement', 'children': ['137', '138', '141']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '140', 'type': 'identifier', 'children': [], 'value': '_callbacks'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'try_statement', 'children': ['143', '149']},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'callback'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '149', 'type': 'except_clause', 'children': ['150']},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'raise_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'NotCallableOrErrorInCall'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '%'},{'id': '156', 'type': 'string', 'children': [], 'value': '"Could not call callback for parameter %s"'},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'name'} | def _set_value(self, new_value):
if self.min_value is not None and new_value < self.min_value:
raise SettingOutOfBounds(
"Trying to set parameter {0} = {1}, which is less than the minimum allowed {2}".format(
self.name, new_value, self.min_value))
if self.max_value is not None and new_value > self.max_value:
raise SettingOutOfBounds(
"Trying to set parameter {0} = {1}, which is more than the maximum allowed {2}".format(
self.name, new_value, self.max_value))
if self.has_auxiliary_variable():
with warnings.catch_warnings():
warnings.simplefilter("always", RuntimeWarning)
warnings.warn("You are trying to assign to a parameter which is either linked or "
"has auxiliary variables. The assignment has no effect.", RuntimeWarning)
if self._transformation is None:
new_internal_value = new_value
else:
new_internal_value = self._transformation.forward(new_value)
if new_internal_value != self._internal_value:
self._internal_value = new_internal_value
for callback in self._callbacks:
try:
callback(self)
except:
raise NotCallableOrErrorInCall("Could not call callback for parameter %s" % self.name) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_uninformative_prior'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'prior_class'},{'id': '6', 'type': 'block', 'children': ['7', '13', '59', '105', '121', '137']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'prior_instance'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'prior_class'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'if_statement', 'children': ['14', '19', '31']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '18'], 'value': 'is'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'min_value'},{'id': '18', 'type': 'None', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'raise_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ParameterMustHaveBounds'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'binary_operator', 'children': ['25', '28'], 'value': '%'},{'id': '25', 'type': 'concatenated_string', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': '"Parameter %s does not have a defined minimum. Set one first, then re-run "'},{'id': '27', 'type': 'string', 'children': [], 'value': '"set_uninformative_prior"'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '31', 'type': 'else_clause', 'children': ['32']},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'try_statement', 'children': ['34', '43']},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'prior_instance'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'lower_bound'},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'min_value'},{'id': '43', 'type': 'except_clause', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'SettingOutOfBounds'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'raise_statement', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'SettingOutOfBounds'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'binary_operator', 'children': ['51', '52'], 'value': '%'},{'id': '51', 'type': 'string', 'children': [], 'value': '"Cannot use minimum of %s for prior %s"'},{'id': '52', 'type': 'tuple', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'min_value'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'prior_instance'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '59', 'type': 'if_statement', 'children': ['60', '65', '77']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '64'], 'value': 'is'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'max_value'},{'id': '64', 'type': 'None', 'children': []},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'raise_statement', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'ParameterMustHaveBounds'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'binary_operator', 'children': ['71', '74'], 'value': '%'},{'id': '71', 'type': 'concatenated_string', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': '"Parameter %s does not have a defined maximum. Set one first, then re-run "'},{'id': '73', 'type': 'string', 'children': [], 'value': '"set_uninformative_prior"'},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '77', 'type': 'else_clause', 'children': ['78']},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'try_statement', 'children': ['80', '89']},{'id': '80', 'type': 'block', 'children': ['81']},{'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': 'prior_instance'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'upper_bound'},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'max_value'},{'id': '89', 'type': 'except_clause', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'SettingOutOfBounds'},{'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': 'SettingOutOfBounds'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '%'},{'id': '97', 'type': 'string', 'children': [], 'value': '"Cannot use maximum of %s for prior %s"'},{'id': '98', 'type': 'tuple', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'max_value'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'prior_instance'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '105', 'type': 'assert_statement', 'children': ['106', '116']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'isfinite'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'attribute', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'prior_instance'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'upper_bound'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '%'},{'id': '117', 'type': 'string', 'children': [], 'value': '"The parameter %s must have a finite maximum"'},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '121', 'type': 'assert_statement', 'children': ['122', '132']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'isfinite'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'attribute', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'prior_instance'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'lower_bound'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '%'},{'id': '133', 'type': 'string', 'children': [], 'value': '"The parameter %s must have a finite minimum"'},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '141', 'type': 'identifier', 'children': [], 'value': '_set_prior'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'prior_instance'} | def set_uninformative_prior(self, prior_class):
prior_instance = prior_class()
if self.min_value is None:
raise ParameterMustHaveBounds("Parameter %s does not have a defined minimum. Set one first, then re-run "
"set_uninformative_prior" % self.path)
else:
try:
prior_instance.lower_bound = self.min_value
except SettingOutOfBounds:
raise SettingOutOfBounds("Cannot use minimum of %s for prior %s" % (self.min_value,
prior_instance.name))
if self.max_value is None:
raise ParameterMustHaveBounds("Parameter %s does not have a defined maximum. Set one first, then re-run "
"set_uninformative_prior" % self.path)
else:
try:
prior_instance.upper_bound = self.max_value
except SettingOutOfBounds:
raise SettingOutOfBounds("Cannot use maximum of %s for prior %s" % (self.max_value,
prior_instance.name))
assert np.isfinite(prior_instance.upper_bound.value),"The parameter %s must have a finite maximum" % self.name
assert np.isfinite(prior_instance.lower_bound.value),"The parameter %s must have a finite minimum" % self.name
self._set_prior(prior_instance) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_library'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'library_root'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'additional_places'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '20']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'first_guess'},{'id': '12', 'type': 'call', 'children': ['13', '18']},{'id': '13', 'type': 'attribute', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ctypes'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'find_library'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'library_root'},{'id': '20', 'type': 'if_statement', 'children': ['21', '24', '89']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'first_guess'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'if_statement', 'children': ['26', '40', '48', '78']},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '39'], 'value': '>='},{'id': '27', 'type': 'call', 'children': ['28', '37']},{'id': '28', 'type': 'attribute', 'children': ['29', '36']},{'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': 'sys'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': '"linux"'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'expression_list', 'children': ['43', '47']},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'sanitize_lib_name'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'first_guess'},{'id': '47', 'type': 'None', 'children': []},{'id': '48', 'type': 'elif_clause', 'children': ['49', '63']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '62'], 'value': '>='},{'id': '50', 'type': 'call', 'children': ['51', '60']},{'id': '51', 'type': 'attribute', 'children': ['52', '59']},{'id': '52', 'type': 'call', 'children': ['53', '58']},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'string', 'children': [], 'value': '"darwin"'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'expression_list', 'children': ['66', '70']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sanitize_lib_name'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'first_guess'},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'first_guess'},{'id': '78', 'type': 'else_clause', 'children': ['79']},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'raise_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '%'},{'id': '85', 'type': 'string', 'children': [], 'value': '"Platform %s is not supported"'},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '89', 'type': 'else_clause', 'children': ['90']},{'id': '90', 'type': 'block', 'children': ['91', '168', '180', '184', '188', '270']},{'id': '91', 'type': 'if_statement', 'children': ['92', '106', '124', '157']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '105'], 'value': '>='},{'id': '93', 'type': 'call', 'children': ['94', '103']},{'id': '94', 'type': 'attribute', 'children': ['95', '102']},{'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': 'sys'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '101', 'type': 'argument_list', 'children': []},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': '"linux"'},{'id': '105', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'possible_locations'},{'id': '110', 'type': 'call', 'children': ['111', '122']},{'id': '111', 'type': 'attribute', 'children': ['112', '121']},{'id': '112', 'type': 'call', 'children': ['113', '118']},{'id': '113', 'type': 'attribute', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '118', 'type': 'argument_list', 'children': ['119', '120']},{'id': '119', 'type': 'string', 'children': [], 'value': '"LD_LIBRARY_PATH"'},{'id': '120', 'type': 'string', 'children': [], 'value': '""'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'string', 'children': [], 'value': '":"'},{'id': '124', 'type': 'elif_clause', 'children': ['125', '139']},{'id': '125', 'type': 'comparison_operator', 'children': ['126', '138'], 'value': '>='},{'id': '126', 'type': 'call', 'children': ['127', '136']},{'id': '127', 'type': 'attribute', 'children': ['128', '135']},{'id': '128', 'type': 'call', 'children': ['129', '134']},{'id': '129', 'type': 'attribute', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '134', 'type': 'argument_list', 'children': []},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'string', 'children': [], 'value': '"darwin"'},{'id': '138', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'possible_locations'},{'id': '143', 'type': 'call', 'children': ['144', '155']},{'id': '144', 'type': 'attribute', 'children': ['145', '154']},{'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': 'os'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'environ'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'string', 'children': [], 'value': '"DYLD_LIBRARY_PATH"'},{'id': '153', 'type': 'string', 'children': [], 'value': '""'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'string', 'children': [], 'value': '":"'},{'id': '157', 'type': 'else_clause', 'children': ['158']},{'id': '158', 'type': 'block', 'children': ['159']},{'id': '159', 'type': 'raise_statement', 'children': ['160']},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '%'},{'id': '164', 'type': 'string', 'children': [], 'value': '"Platform %s is not supported"'},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'platform'},{'id': '168', 'type': 'if_statement', 'children': ['169', '172']},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': 'is'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'additional_places'},{'id': '171', 'type': 'None', 'children': []},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'possible_locations'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'additional_places'},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'library_name'},{'id': '183', 'type': 'None', 'children': []},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'library_dir'},{'id': '187', 'type': 'None', 'children': []},{'id': '188', 'type': 'for_statement', 'children': ['189', '190', '191']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'search_path'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'possible_locations'},{'id': '191', 'type': 'block', 'children': ['192', '198', '217', '264']},{'id': '192', 'type': 'if_statement', 'children': ['193', '196']},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '195'], 'value': '=='},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'search_path'},{'id': '195', 'type': 'string', 'children': [], 'value': '""'},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'continue_statement', 'children': []},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '212']},{'id': '207', 'type': 'attribute', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '212', 'type': 'argument_list', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'search_path'},{'id': '214', 'type': 'binary_operator', 'children': ['215', '216'], 'value': '%'},{'id': '215', 'type': 'string', 'children': [], 'value': '"lib%s*"'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'library_root'},{'id': '217', 'type': 'if_statement', 'children': ['218', '224', '261']},{'id': '218', 'type': 'comparison_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': 'results'},{'id': '223', 'type': 'integer', 'children': [], 'value': '1'},{'id': '224', 'type': 'block', 'children': ['225']},{'id': '225', 'type': 'for_statement', 'children': ['226', '227', '228']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'if_statement', 'children': ['230', '248', '250']},{'id': '230', 'type': 'comparison_operator', 'children': ['231', '247'], 'value': 'is'},{'id': '231', 'type': 'call', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '235', 'type': 'argument_list', 'children': ['236', '239']},{'id': '236', 'type': 'binary_operator', 'children': ['237', '238'], 'value': '%'},{'id': '237', 'type': 'string', 'children': [], 'value': '"lib%s[\\-_\\.]"'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'library_root'},{'id': '239', 'type': 'call', 'children': ['240', '245']},{'id': '240', 'type': 'attribute', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '245', 'type': 'argument_list', 'children': ['246']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '247', 'type': 'None', 'children': []},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'continue_statement', 'children': []},{'id': '250', 'type': 'else_clause', 'children': ['251']},{'id': '251', 'type': 'block', 'children': ['252', '256', '260']},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'library_name'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'library_dir'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'search_path'},{'id': '260', 'type': 'break_statement', 'children': []},{'id': '261', 'type': 'else_clause', 'children': ['262']},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'continue_statement', 'children': []},{'id': '264', 'type': 'if_statement', 'children': ['265', '268']},{'id': '265', 'type': 'comparison_operator', 'children': ['266', '267'], 'value': 'is'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'library_name'},{'id': '267', 'type': 'None', 'children': []},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'break_statement', 'children': []},{'id': '270', 'type': 'if_statement', 'children': ['271', '274', '279']},{'id': '271', 'type': 'comparison_operator', 'children': ['272', '273'], 'value': 'is'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'library_name'},{'id': '273', 'type': 'None', 'children': []},{'id': '274', 'type': 'block', 'children': ['275']},{'id': '275', 'type': 'return_statement', 'children': ['276']},{'id': '276', 'type': 'expression_list', 'children': ['277', '278']},{'id': '277', 'type': 'None', 'children': []},{'id': '278', 'type': 'None', 'children': []},{'id': '279', 'type': 'else_clause', 'children': ['280']},{'id': '280', 'type': 'block', 'children': ['281']},{'id': '281', 'type': 'return_statement', 'children': ['282']},{'id': '282', 'type': 'expression_list', 'children': ['283', '287']},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'sanitize_lib_name'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'library_name'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'library_dir'} | def find_library(library_root, additional_places=None):
first_guess = ctypes.util.find_library(library_root)
if first_guess is not None:
if sys.platform.lower().find("linux") >= 0:
return sanitize_lib_name(first_guess), None
elif sys.platform.lower().find("darwin") >= 0:
return sanitize_lib_name(first_guess), os.path.dirname(first_guess)
else:
raise NotImplementedError("Platform %s is not supported" % sys.platform)
else:
if sys.platform.lower().find("linux") >= 0:
possible_locations = os.environ.get("LD_LIBRARY_PATH", "").split(":")
elif sys.platform.lower().find("darwin") >= 0:
possible_locations = os.environ.get("DYLD_LIBRARY_PATH", "").split(":")
else:
raise NotImplementedError("Platform %s is not supported" % sys.platform)
if additional_places is not None:
possible_locations.extend(additional_places)
library_name = None
library_dir = None
for search_path in possible_locations:
if search_path == "":
continue
results = glob.glob(os.path.join(search_path, "lib%s*" % library_root))
if len(results) >= 1:
for result in results:
if re.match("lib%s[\-_\.]" % library_root, os.path.basename(result)) is None:
continue
else:
library_name = result
library_dir = search_path
break
else:
continue
if library_name is not None:
break
if library_name is None:
return None, None
else:
return sanitize_lib_name(library_name), library_dir |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'LDA_discriminants'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '6', 'type': 'block', 'children': ['7', '25', '35']},{'id': '7', 'type': 'try_statement', 'children': ['8', '18']},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '18', 'type': 'except_clause', 'children': ['19']},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'raise_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': "'Impossible to convert x to a numpy array.'"},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '30']},{'id': '27', 'type': 'pattern_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'eigen_values'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'eigen_vectors'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'LDA_base'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'eigen_values'},{'id': '38', 'type': 'call', 'children': ['39', '44']},{'id': '39', 'type': 'attribute', 'children': ['40', '43']},{'id': '40', 'type': '()', 'children': ['41']},{'id': '41', 'type': 'unary_operator', 'children': ['42'], 'value': '-'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'eigen_values'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '44', 'type': 'argument_list', 'children': []} | def LDA_discriminants(x, labels):
try:
x = np.array(x)
except:
raise ValueError('Impossible to convert x to a numpy array.')
eigen_values, eigen_vectors = LDA_base(x, labels)
return eigen_values[(-eigen_values).argsort()] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'train'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'epochs'},{'id': '9', 'type': 'integer', 'children': [], 'value': '10'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'shuffle'},{'id': '12', 'type': 'False', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '21', '35', '53', '95', '122', '157', '166', '202', '272']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '21', 'type': 'if_statement', 'children': ['22', '29']},{'id': '22', 'type': 'not_operator', 'children': ['23']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '28'], 'value': '=='},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'raise_statement', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'string', 'children': [], 'value': "'The length of vector d and matrix x must agree.'"},{'id': '35', 'type': 'if_statement', 'children': ['36', '47']},{'id': '36', 'type': 'not_operator', 'children': ['37']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '44'], 'value': '=='},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'n_input'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'raise_statement', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': "'The number of network inputs is not correct.'"},{'id': '53', 'type': 'if_statement', 'children': ['54', '59', '76']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '58'], 'value': '=='},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'outputs'},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'if_statement', 'children': ['61', '70']},{'id': '61', 'type': 'not_operator', 'children': ['62']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '69'], 'value': '=='},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'raise_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'string', 'children': [], 'value': "'For one output MLP the d must have one dimension'"},{'id': '76', 'type': 'else_clause', 'children': ['77']},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'if_statement', 'children': ['79', '89']},{'id': '79', 'type': 'not_operator', 'children': ['80']},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '86'], 'value': '=='},{'id': '81', 'type': 'subscript', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'outputs'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'raise_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'string', 'children': [], 'value': "'The number of outputs must agree with number of columns in d'"},{'id': '95', 'type': 'try_statement', 'children': ['96', '115']},{'id': '96', 'type': 'block', 'children': ['97', '106']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '100', 'type': 'call', 'children': ['101', '104']},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '104', 'type': 'argument_list', 'children': ['105']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '115', 'type': 'except_clause', 'children': ['116']},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'raise_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'string', 'children': [], 'value': "'Impossible to convert x or d to a numpy array'"},{'id': '122', 'type': 'if_statement', 'children': ['123', '128', '140']},{'id': '123', 'type': 'comparison_operator', 'children': ['124', '127'], 'value': '=='},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'outputs'},{'id': '127', 'type': 'integer', 'children': [], 'value': '1'},{'id': '128', 'type': 'block', 'children': ['129']},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '*'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'epochs'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '140', 'type': 'else_clause', 'children': ['141']},{'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': 'e'},{'id': '145', 'type': 'call', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'tuple', 'children': ['151', '154']},{'id': '151', 'type': 'binary_operator', 'children': ['152', '153'], 'value': '*'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'epochs'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'outputs'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'MSE'},{'id': '160', 'type': 'call', 'children': ['161', '164']},{'id': '161', 'type': 'attribute', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'zeros'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'epochs'},{'id': '166', 'type': 'if_statement', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'shuffle'},{'id': '168', 'type': 'block', 'children': ['169', '181', '190', '196']},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'randomize'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'call', 'children': ['183', '188']},{'id': '183', 'type': 'attribute', 'children': ['184', '187']},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'shuffle'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'randomize'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'randomize'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'randomize'},{'id': '202', 'type': 'for_statement', 'children': ['203', '204', '208']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'epoch'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'epochs'},{'id': '208', 'type': 'block', 'children': ['209', '243']},{'id': '209', 'type': 'for_statement', 'children': ['210', '211', '215']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '213', 'type': 'argument_list', 'children': ['214']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '215', 'type': 'block', 'children': ['216', '225']},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'predict'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '235']},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '229', 'type': 'binary_operator', 'children': ['230', '234'], 'value': '+'},{'id': '230', 'type': '()', 'children': ['231']},{'id': '231', 'type': 'binary_operator', 'children': ['232', '233'], 'value': '*'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'epoch'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '239', 'type': 'argument_list', 'children': ['240']},{'id': '240', 'type': 'subscript', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '243', 'type': 'expression_statement', 'children': ['244']},{'id': '244', 'type': 'assignment', 'children': ['245', '248']},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'MSE'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'epoch'},{'id': '248', 'type': 'binary_operator', 'children': ['249', '271'], 'value': '/'},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'binary_operator', 'children': ['255', '270'], 'value': '**'},{'id': '255', 'type': 'subscript', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '257', 'type': 'slice', 'children': ['258', '261', '262']},{'id': '258', 'type': 'binary_operator', 'children': ['259', '260'], 'value': '*'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'epoch'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '261', 'type': 'colon', 'children': []},{'id': '262', 'type': 'binary_operator', 'children': ['263', '269'], 'value': '-'},{'id': '263', 'type': 'binary_operator', 'children': ['264', '268'], 'value': '*'},{'id': '264', 'type': '()', 'children': ['265']},{'id': '265', 'type': 'binary_operator', 'children': ['266', '267'], 'value': '+'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'epoch'},{'id': '267', 'type': 'integer', 'children': [], 'value': '1'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '269', 'type': 'integer', 'children': [], 'value': '1'},{'id': '270', 'type': 'integer', 'children': [], 'value': '2'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'N'},{'id': '272', 'type': 'return_statement', 'children': ['273']},{'id': '273', 'type': 'expression_list', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'MSE'} | def train(self, x, d, epochs=10, shuffle=False):
N = len(x)
if not len(d) == N:
raise ValueError('The length of vector d and matrix x must agree.')
if not len(x[0]) == self.n_input:
raise ValueError('The number of network inputs is not correct.')
if self.outputs == 1:
if not len(d.shape) == 1:
raise ValueError('For one output MLP the d must have one dimension')
else:
if not d.shape[1] == self.outputs:
raise ValueError('The number of outputs must agree with number of columns in d')
try:
x = np.array(x)
d = np.array(d)
except:
raise ValueError('Impossible to convert x or d to a numpy array')
if self.outputs == 1:
e = np.zeros(epochs*N)
else:
e = np.zeros((epochs*N, self.outputs))
MSE = np.zeros(epochs)
if shuffle:
randomize = np.arange(len(x))
np.random.shuffle(randomize)
x = x[randomize]
d = d[randomize]
for epoch in range(epochs):
for k in range(N):
self.predict(x[k])
e[(epoch*N)+k] = self.update(d[k])
MSE[epoch] = np.sum(e[epoch*N:(epoch+1)*N-1]**2) / N
return e, MSE |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'PCA_components'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'block', 'children': ['6', '24', '44', '58']},{'id': '6', 'type': 'try_statement', 'children': ['7', '17']},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '17', 'type': 'except_clause', 'children': ['18']},{'id': '18', 'type': 'block', 'children': ['19']},{'id': '19', 'type': 'raise_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': "'Impossible to convert x to a numpy array.'"},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '29']},{'id': '26', 'type': 'pattern_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'eigen_values'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'eigen_vectors'},{'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': 'np'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'eig'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cov'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'eigen_order'},{'id': '47', 'type': 'subscript', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'eigen_vectors'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '51', 'type': 'call', 'children': ['52', '57']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': '()', 'children': ['54']},{'id': '54', 'type': 'unary_operator', 'children': ['55'], 'value': '-'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'eigen_values'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'subscript', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'eigen_values'},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': '()', 'children': ['64']},{'id': '64', 'type': 'unary_operator', 'children': ['65'], 'value': '-'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'eigen_values'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '67', 'type': 'argument_list', 'children': []} | def PCA_components(x):
try:
x = np.array(x)
except:
raise ValueError('Impossible to convert x to a numpy array.')
eigen_values, eigen_vectors = np.linalg.eig(np.cov(x.T))
eigen_order = eigen_vectors.T[(-eigen_values).argsort()]
return eigen_values[(-eigen_values).argsort()] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_mpl_colorbar'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dfr'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fig'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'dend'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '10', 'type': 'string', 'children': [], 'value': '"row"'},{'id': '11', 'type': 'block', 'children': ['12', '39', '60', '64', '103', '112', '207', '212']},{'id': '12', 'type': 'for_statement', 'children': ['13', '14', '23']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '14', 'type': 'subscript', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'dfr'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '18', 'type': 'subscript', 'children': ['19', '22']},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'dend'},{'id': '21', 'type': 'string', 'children': [], 'value': '"dendrogram"'},{'id': '22', 'type': 'string', 'children': [], 'value': '"leaves"'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'if_statement', 'children': ['25', '30']},{'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': 'params'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '38']},{'id': '33', 'type': 'subscript', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'classdict'},{'id': '42', 'type': 'dictionary_comprehension', 'children': ['43', '46']},{'id': '43', 'type': 'pair', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '46', 'type': 'for_in_clause', 'children': ['47', '50']},{'id': '47', 'type': 'tuple_pattern', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '52', 'type': 'argument_list', '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': 'params'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '59', 'type': 'argument_list', 'children': []},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'cblist'},{'id': '63', 'type': 'list', 'children': [], 'value': '[]'},{'id': '64', 'type': 'for_statement', 'children': ['65', '66', '75']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '66', 'type': 'subscript', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'dfr'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '70', 'type': 'subscript', 'children': ['71', '74']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'dend'},{'id': '73', 'type': 'string', 'children': [], 'value': '"dendrogram"'},{'id': '74', 'type': 'string', 'children': [], 'value': '"leaves"'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'try_statement', 'children': ['77', '91']},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'cblist'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'classdict'},{'id': '86', 'type': 'subscript', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'classes'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '91', 'type': 'except_clause', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'cblist'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'classdict'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'colbar'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'cblist'},{'id': '112', 'type': 'if_statement', 'children': ['113', '116', '164']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': '=='},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'orientation'},{'id': '115', 'type': 'string', 'children': [], 'value': '"row"'},{'id': '116', 'type': 'block', 'children': ['117', '131']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'assignment', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'cbaxes'},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'fig'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'add_subplot'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'subscript', 'children': ['126', '129', '130']},{'id': '126', 'type': 'subscript', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'dend'},{'id': '128', 'type': 'string', 'children': [], 'value': '"gridspec"'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'integer', 'children': [], 'value': '1'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'cbaxes'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'imshow'},{'id': '136', 'type': 'argument_list', 'children': ['137', '145', '155', '158', '161']},{'id': '137', 'type': 'list_comprehension', 'children': ['138', '140']},{'id': '138', 'type': 'list', 'children': ['139'], 'value': '[cbar]'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'cbar'},{'id': '140', 'type': 'for_in_clause', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'cbar'},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'colbar'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '147', 'type': 'call', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'get_cmap'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'pyani_config'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'MPL_CBAR'},{'id': '155', 'type': 'keyword_argument', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'interpolation'},{'id': '157', 'type': 'string', 'children': [], 'value': '"nearest"'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'aspect'},{'id': '160', 'type': 'string', 'children': [], 'value': '"auto"'},{'id': '161', 'type': 'keyword_argument', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '163', 'type': 'string', 'children': [], 'value': '"lower"'},{'id': '164', 'type': 'else_clause', 'children': ['165']},{'id': '165', 'type': 'block', 'children': ['166', '180']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'cbaxes'},{'id': '169', 'type': 'call', 'children': ['170', '173']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'fig'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'add_subplot'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'subscript', 'children': ['175', '178', '179']},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'dend'},{'id': '177', 'type': 'string', 'children': [], 'value': '"gridspec"'},{'id': '178', 'type': 'integer', 'children': [], 'value': '1'},{'id': '179', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'cbaxes'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'imshow'},{'id': '185', 'type': 'argument_list', 'children': ['186', '188', '198', '201', '204']},{'id': '186', 'type': 'list', 'children': ['187'], 'value': '[colbar]'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'colbar'},{'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'cmap'},{'id': '190', 'type': 'call', 'children': ['191', '194']},{'id': '191', 'type': 'attribute', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'plt'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'get_cmap'},{'id': '194', 'type': 'argument_list', 'children': ['195']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'pyani_config'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'MPL_CBAR'},{'id': '198', 'type': 'keyword_argument', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'interpolation'},{'id': '200', 'type': 'string', 'children': [], 'value': '"nearest"'},{'id': '201', 'type': 'keyword_argument', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'aspect'},{'id': '203', 'type': 'string', 'children': [], 'value': '"auto"'},{'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'origin'},{'id': '206', 'type': 'string', 'children': [], 'value': '"lower"'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'clean_axis'},{'id': '210', 'type': 'argument_list', 'children': ['211']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'cbaxes'},{'id': '212', 'type': 'return_statement', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'colbar'} | def add_mpl_colorbar(dfr, fig, dend, params, orientation="row"):
for name in dfr.index[dend["dendrogram"]["leaves"]]:
if name not in params.classes:
params.classes[name] = name
classdict = {cls: idx for (idx, cls) in enumerate(params.classes.values())}
cblist = []
for name in dfr.index[dend["dendrogram"]["leaves"]]:
try:
cblist.append(classdict[params.classes[name]])
except KeyError:
cblist.append(classdict[name])
colbar = pd.Series(cblist)
if orientation == "row":
cbaxes = fig.add_subplot(dend["gridspec"][0, 1])
cbaxes.imshow(
[[cbar] for cbar in colbar.values],
cmap=plt.get_cmap(pyani_config.MPL_CBAR),
interpolation="nearest",
aspect="auto",
origin="lower",
)
else:
cbaxes = fig.add_subplot(dend["gridspec"][1, 0])
cbaxes.imshow(
[colbar],
cmap=plt.get_cmap(pyani_config.MPL_CBAR),
interpolation="nearest",
aspect="auto",
origin="lower",
)
clean_axis(cbaxes)
return colbar |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'calculate_anim'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'infiles'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '6', 'type': 'block', 'children': ['7', '14', '21', '37', '45', '226', '233', '246', '317', '336']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'string', 'children': [], 'value': '"Running ANIm"'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': '"Generating NUCmer command-lines"'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'deltadir'},{'id': '24', 'type': 'call', 'children': ['25', '30']},{'id': '25', 'type': 'attribute', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '30', 'type': 'argument_list', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'outdirname'},{'id': '34', 'type': 'subscript', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ALIGNDIR'},{'id': '36', 'type': 'string', 'children': [], 'value': '"ANIm"'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '42', 'type': 'argument_list', 'children': ['43', '44']},{'id': '43', 'type': 'string', 'children': [], 'value': '"Writing nucmer output to %s"'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'deltadir'},{'id': '45', 'type': 'if_statement', 'children': ['46', '50', '217']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'skip_nucmer'},{'id': '50', 'type': 'block', 'children': ['51', '83']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'anim'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'generate_nucmer_jobs'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60', '63', '68', '73', '78']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'infiles'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'outdirname'},{'id': '63', 'type': 'keyword_argument', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'nucmer_exe'},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'nucmer_exe'},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'filter_exe'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'filter_exe'},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'maxmatch'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'maxmatch'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'jobprefix'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'jobprefix'},{'id': '83', 'type': 'if_statement', 'children': ['84', '89', '173']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '88'], 'value': '=='},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'scheduler'},{'id': '88', 'type': 'string', 'children': [], 'value': '"multiprocessing"'},{'id': '89', 'type': 'block', 'children': ['90', '97', '125', '142', '150']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'string', 'children': [], 'value': '"Running jobs with multiprocessing"'},{'id': '97', 'type': 'if_statement', 'children': ['98', '103', '113']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '102'], 'value': 'is'},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '102', 'type': 'None', 'children': []},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'binary_operator', 'children': ['111', '112'], 'value': '+'},{'id': '111', 'type': 'string', 'children': [], 'value': '"(using maximum number of available "'},{'id': '112', 'type': 'string', 'children': [], 'value': '"worker threads)"'},{'id': '113', 'type': 'else_clause', 'children': ['114']},{'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': 'logger'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122']},{'id': '121', 'type': 'string', 'children': [], 'value': '"(using %d worker threads, if available)"'},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'cumval'},{'id': '128', 'type': 'call', 'children': ['129', '132']},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'run_mp'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'run_dependency_graph'},{'id': '132', 'type': 'argument_list', 'children': ['133', '134', '139']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '139', 'type': 'keyword_argument', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149']},{'id': '148', 'type': 'string', 'children': [], 'value': '"Cumulative return value: %d"'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'cumval'},{'id': '150', 'type': 'if_statement', 'children': ['151', '154', '164']},{'id': '151', 'type': 'comparison_operator', 'children': ['152', '153'], 'value': '<'},{'id': '152', 'type': 'integer', 'children': [], 'value': '0'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'cumval'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '+'},{'id': '162', 'type': 'string', 'children': [], 'value': '"At least one NUCmer comparison failed. "'},{'id': '163', 'type': 'string', 'children': [], 'value': '"ANIm may fail."'},{'id': '164', 'type': 'else_clause', 'children': ['165']},{'id': '165', 'type': 'block', 'children': ['166']},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'string', 'children': [], 'value': '"All multiprocessing jobs complete."'},{'id': '173', 'type': 'else_clause', 'children': ['174']},{'id': '174', 'type': 'block', 'children': ['175', '182', '192']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'string', 'children': [], 'value': '"Running jobs with SGE"'},{'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': 'logger'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189']},{'id': '188', 'type': 'string', 'children': [], 'value': '"Jobarray group size set to %d"'},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'sgegroupsize'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'run_sge'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'run_dependency_graph'},{'id': '197', 'type': 'argument_list', 'children': ['198', '199', '202', '207', '212']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'id': '199', 'type': 'keyword_argument', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'jgprefix'},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'jobprefix'},{'id': '207', 'type': 'keyword_argument', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'sgegroupsize'},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'sgegroupsize'},{'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'sgeargs'},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'sgeargs'},{'id': '217', 'type': 'else_clause', 'children': ['218']},{'id': '218', 'type': 'block', 'children': ['219']},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'string', 'children': [], 'value': '"Skipping NUCmer run (as instructed)!"'},{'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': 'logger'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'string', 'children': [], 'value': '"Processing NUCmer .delta files."'},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'assignment', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'anim'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'process_deltadir'},{'id': '240', 'type': 'argument_list', 'children': ['241', '242', '243']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'deltadir'},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '246', 'type': 'if_statement', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'zero_error'},{'id': '250', 'type': 'block', 'children': ['251']},{'id': '251', 'type': 'if_statement', 'children': ['252', '262']},{'id': '252', 'type': 'boolean_operator', 'children': ['253', '257'], 'value': 'and'},{'id': '253', 'type': 'not_operator', 'children': ['254']},{'id': '254', 'type': 'attribute', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'skip_nucmer'},{'id': '257', 'type': 'comparison_operator', 'children': ['258', '261'], 'value': '=='},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'scheduler'},{'id': '261', 'type': 'string', 'children': [], 'value': '"multiprocessing"'},{'id': '262', 'type': 'block', 'children': ['263']},{'id': '263', 'type': 'if_statement', 'children': ['264', '267', '293']},{'id': '264', 'type': 'comparison_operator', 'children': ['265', '266'], 'value': '<'},{'id': '265', 'type': 'integer', 'children': [], 'value': '0'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'cumval'},{'id': '267', 'type': 'block', 'children': ['268', '277', '286']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'call', 'children': ['270', '273']},{'id': '270', 'type': 'attribute', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'binary_operator', 'children': ['275', '276'], 'value': '+'},{'id': '275', 'type': 'string', 'children': [], 'value': '"This has possibly been a NUCmer run failure, "'},{'id': '276', 'type': 'string', 'children': [], 'value': '"please investigate"'},{'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': 'logger'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '282', 'type': 'argument_list', 'children': ['283']},{'id': '283', 'type': 'call', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'last_exception'},{'id': '285', 'type': 'argument_list', 'children': []},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'call', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'exit'},{'id': '291', 'type': 'argument_list', 'children': ['292']},{'id': '292', 'type': 'integer', 'children': [], 'value': '1'},{'id': '293', 'type': 'else_clause', 'children': ['294']},{'id': '294', 'type': 'block', 'children': ['295', '306']},{'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': 'logger'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'binary_operator', 'children': ['302', '305'], 'value': '+'},{'id': '302', 'type': 'binary_operator', 'children': ['303', '304'], 'value': '+'},{'id': '303', 'type': 'string', 'children': [], 'value': '"This is possibly due to a NUCmer comparison "'},{'id': '304', 'type': 'string', 'children': [], 'value': '"being too distant for use. Please consider "'},{'id': '305', 'type': 'string', 'children': [], 'value': '"using the --maxmatch option."'},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'call', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'binary_operator', 'children': ['313', '316'], 'value': '+'},{'id': '313', 'type': 'binary_operator', 'children': ['314', '315'], 'value': '+'},{'id': '314', 'type': 'string', 'children': [], 'value': '"This is alternatively due to NUCmer run "'},{'id': '315', 'type': 'string', 'children': [], 'value': '"failure, analysis will continue, but please "'},{'id': '316', 'type': 'string', 'children': [], 'value': '"investigate."'},{'id': '317', 'type': 'if_statement', 'children': ['318', '322']},{'id': '318', 'type': 'not_operator', 'children': ['319']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'nocompress'},{'id': '322', 'type': 'block', 'children': ['323', '331']},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'call', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '328', 'type': 'argument_list', 'children': ['329', '330']},{'id': '329', 'type': 'string', 'children': [], 'value': '"Compressing/deleting %s"'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'deltadir'},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'call', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'compress_delete_outdir'},{'id': '334', 'type': 'argument_list', 'children': ['335']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'deltadir'},{'id': '336', 'type': 'return_statement', 'children': ['337']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'results'} | def calculate_anim(infiles, org_lengths):
logger.info("Running ANIm")
logger.info("Generating NUCmer command-lines")
deltadir = os.path.join(args.outdirname, ALIGNDIR["ANIm"])
logger.info("Writing nucmer output to %s", deltadir)
if not args.skip_nucmer:
joblist = anim.generate_nucmer_jobs(
infiles,
args.outdirname,
nucmer_exe=args.nucmer_exe,
filter_exe=args.filter_exe,
maxmatch=args.maxmatch,
jobprefix=args.jobprefix,
)
if args.scheduler == "multiprocessing":
logger.info("Running jobs with multiprocessing")
if args.workers is None:
logger.info("(using maximum number of available " + "worker threads)")
else:
logger.info("(using %d worker threads, if available)", args.workers)
cumval = run_mp.run_dependency_graph(
joblist, workers=args.workers, logger=logger
)
logger.info("Cumulative return value: %d", cumval)
if 0 < cumval:
logger.warning(
"At least one NUCmer comparison failed. " + "ANIm may fail."
)
else:
logger.info("All multiprocessing jobs complete.")
else:
logger.info("Running jobs with SGE")
logger.info("Jobarray group size set to %d", args.sgegroupsize)
run_sge.run_dependency_graph(
joblist,
logger=logger,
jgprefix=args.jobprefix,
sgegroupsize=args.sgegroupsize,
sgeargs=args.sgeargs,
)
else:
logger.warning("Skipping NUCmer run (as instructed)!")
logger.info("Processing NUCmer .delta files.")
results = anim.process_deltadir(deltadir, org_lengths, logger=logger)
if results.zero_error:
if not args.skip_nucmer and args.scheduler == "multiprocessing":
if 0 < cumval:
logger.error(
"This has possibly been a NUCmer run failure, "
+ "please investigate"
)
logger.error(last_exception())
sys.exit(1)
else:
logger.error(
"This is possibly due to a NUCmer comparison "
+ "being too distant for use. Please consider "
+ "using the --maxmatch option."
)
logger.error(
"This is alternatively due to NUCmer run "
+ "failure, analysis will continue, but please "
+ "investigate."
)
if not args.nocompress:
logger.info("Compressing/deleting %s", deltadir)
compress_delete_outdir(deltadir)
return results |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'unified_anib'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'infiles'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '6', 'type': 'block', 'children': ['7', '17', '35', '43', '290', '300', '370', '389']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '12', 'type': 'argument_list', 'children': ['13', '14']},{'id': '13', 'type': 'string', 'children': [], 'value': '"Running %s"'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'blastdir'},{'id': '20', 'type': 'call', 'children': ['21', '26']},{'id': '21', 'type': 'attribute', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '26', 'type': 'argument_list', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'outdirname'},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ALIGNDIR'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': '"Writing BLAST output to %s"'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'blastdir'},{'id': '43', 'type': 'if_statement', 'children': ['44', '48', '239']},{'id': '44', 'type': 'not_operator', 'children': ['45']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'skip_blastn'},{'id': '48', 'type': 'block', 'children': ['49', '59', '74', '102', '109', '128']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': '"Fragmenting input files, and writing to %s"'},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'outdirname'},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '64']},{'id': '61', 'type': 'pattern_list', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'fragfiles'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'fraglengths'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'anib'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'fragment_fasta_files'},{'id': '68', 'type': 'argument_list', 'children': ['69', '70', '71']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'infiles'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'blastdir'},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'fragsize'},{'id': '74', 'type': 'with_statement', 'children': ['75', '93']},{'id': '75', 'type': 'with_clause', 'children': ['76']},{'id': '76', 'type': 'with_item', 'children': ['77']},{'id': '77', 'type': 'as_pattern', 'children': ['78', '91']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '80', 'type': 'argument_list', 'children': ['81', '90']},{'id': '81', 'type': 'call', 'children': ['82', '87']},{'id': '82', 'type': 'attribute', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '87', 'type': 'argument_list', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'blastdir'},{'id': '89', 'type': 'string', 'children': [], 'value': '"fraglengths.json"'},{'id': '90', 'type': 'string', 'children': [], 'value': '"w"'},{'id': '91', 'type': 'as_pattern_target', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'dump'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'fraglengths'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'outfile'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'string', 'children': [], 'value': '"Creating job dependency graph"'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'jobgraph'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'anib'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'make_job_graph'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118', '119']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'infiles'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'fragfiles'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'anib'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'make_blastcmd_builder'},{'id': '123', 'type': 'argument_list', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'blastdir'},{'id': '128', 'type': 'if_statement', 'children': ['129', '134', '220']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': '=='},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'scheduler'},{'id': '133', 'type': 'string', 'children': [], 'value': '"multiprocessing"'},{'id': '134', 'type': 'block', 'children': ['135', '142', '149', '177', '194']},{'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': 'logger'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'string', 'children': [], 'value': '"Running jobs with multiprocessing"'},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'string', 'children': [], 'value': '"Running job dependency graph"'},{'id': '149', 'type': 'if_statement', 'children': ['150', '155', '165']},{'id': '150', 'type': 'comparison_operator', 'children': ['151', '154'], 'value': 'is'},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '154', 'type': 'None', 'children': []},{'id': '155', 'type': 'block', 'children': ['156']},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'binary_operator', 'children': ['163', '164'], 'value': '+'},{'id': '163', 'type': 'string', 'children': [], 'value': '"(using maximum number of available "'},{'id': '164', 'type': 'string', 'children': [], 'value': '"worker threads)"'},{'id': '165', 'type': 'else_clause', 'children': ['166']},{'id': '166', 'type': 'block', 'children': ['167']},{'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': 'logger'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '172', 'type': 'argument_list', 'children': ['173', '174']},{'id': '173', 'type': 'string', 'children': [], 'value': '"(using %d worker threads, if available)"'},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'cumval'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'run_mp'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'run_dependency_graph'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186', '191']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'jobgraph'},{'id': '186', 'type': 'keyword_argument', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'workers'},{'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '194', 'type': 'if_statement', 'children': ['195', '198', '211']},{'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': '<'},{'id': '196', 'type': 'integer', 'children': [], 'value': '0'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'cumval'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '204', 'type': 'argument_list', 'children': ['205', '208']},{'id': '205', 'type': 'binary_operator', 'children': ['206', '207'], 'value': '+'},{'id': '206', 'type': 'string', 'children': [], 'value': '"At least one BLAST run failed. "'},{'id': '207', 'type': 'string', 'children': [], 'value': '"%s may fail."'},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '211', 'type': 'else_clause', 'children': ['212']},{'id': '212', 'type': 'block', 'children': ['213']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'string', 'children': [], 'value': '"All multiprocessing jobs complete."'},{'id': '220', 'type': 'else_clause', 'children': ['221']},{'id': '221', 'type': 'block', 'children': ['222', '232']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'run_sge'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'run_dependency_graph'},{'id': '227', 'type': 'argument_list', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'jobgraph'},{'id': '229', 'type': 'keyword_argument', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '237', 'type': 'argument_list', 'children': ['238']},{'id': '238', 'type': 'string', 'children': [], 'value': '"Running jobs with SGE"'},{'id': '239', 'type': 'else_clause', 'children': ['240']},{'id': '240', 'type': 'block', 'children': ['241', '283']},{'id': '241', 'type': 'if_statement', 'children': ['242', '247', '277']},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '246'], 'value': '=='},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '246', 'type': 'string', 'children': [], 'value': '"ANIblastall"'},{'id': '247', 'type': 'block', 'children': ['248']},{'id': '248', 'type': 'with_statement', 'children': ['249', '267']},{'id': '249', 'type': 'with_clause', 'children': ['250']},{'id': '250', 'type': 'with_item', 'children': ['251']},{'id': '251', 'type': 'as_pattern', 'children': ['252', '265']},{'id': '252', 'type': 'call', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '254', 'type': 'argument_list', 'children': ['255', '264']},{'id': '255', 'type': 'call', 'children': ['256', '261']},{'id': '256', 'type': 'attribute', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '261', 'type': 'argument_list', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'blastdir'},{'id': '263', 'type': 'string', 'children': [], 'value': '"fraglengths.json"'},{'id': '264', 'type': 'string', 'children': [], 'value': '"rU"'},{'id': '265', 'type': 'as_pattern_target', 'children': ['266']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'infile'},{'id': '267', 'type': 'block', 'children': ['268']},{'id': '268', 'type': 'expression_statement', 'children': ['269']},{'id': '269', 'type': 'assignment', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'fraglengths'},{'id': '271', 'type': 'call', 'children': ['272', '275']},{'id': '272', 'type': 'attribute', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '275', 'type': 'argument_list', 'children': ['276']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'infile'},{'id': '277', 'type': 'else_clause', 'children': ['278']},{'id': '278', 'type': 'block', 'children': ['279']},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'assignment', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'fraglengths'},{'id': '282', 'type': 'None', 'children': []},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'call', 'children': ['285', '288']},{'id': '285', 'type': 'attribute', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'string', 'children': [], 'value': '"Skipping BLASTN runs (as instructed)!"'},{'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': 'logger'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '295', 'type': 'argument_list', 'children': ['296', '297']},{'id': '296', 'type': 'string', 'children': [], 'value': '"Processing pairwise %s BLAST output."'},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '300', 'type': 'try_statement', 'children': ['301', '320']},{'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': 'data'},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'anib'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'process_blast'},{'id': '309', 'type': 'argument_list', 'children': ['310', '311', '312', '315']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'blastdir'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '312', 'type': 'keyword_argument', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'fraglengths'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'fraglengths'},{'id': '315', 'type': 'keyword_argument', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '320', 'type': 'except_clause', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'ZeroDivisionError'},{'id': '322', 'type': 'block', 'children': ['323', '330', '361']},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'call', 'children': ['325', '328']},{'id': '325', 'type': 'attribute', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '328', 'type': 'argument_list', 'children': ['329']},{'id': '329', 'type': 'string', 'children': [], 'value': '"One or more BLAST output files has a problem."'},{'id': '330', 'type': 'if_statement', 'children': ['331', '335']},{'id': '331', 'type': 'not_operator', 'children': ['332']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'skip_blastn'},{'id': '335', 'type': 'block', 'children': ['336']},{'id': '336', 'type': 'if_statement', 'children': ['337', '340', '350']},{'id': '337', 'type': 'comparison_operator', 'children': ['338', '339'], 'value': '<'},{'id': '338', 'type': 'integer', 'children': [], 'value': '0'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'cumval'},{'id': '340', 'type': 'block', 'children': ['341']},{'id': '341', 'type': 'expression_statement', 'children': ['342']},{'id': '342', 'type': 'call', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '346', 'type': 'argument_list', 'children': ['347']},{'id': '347', 'type': 'binary_operator', 'children': ['348', '349'], 'value': '+'},{'id': '348', 'type': 'string', 'children': [], 'value': '"This is possibly due to BLASTN run failure, "'},{'id': '349', 'type': 'string', 'children': [], 'value': '"please investigate"'},{'id': '350', 'type': 'else_clause', 'children': ['351']},{'id': '351', 'type': 'block', 'children': ['352']},{'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': 'logger'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '357', 'type': 'argument_list', 'children': ['358']},{'id': '358', 'type': 'binary_operator', 'children': ['359', '360'], 'value': '+'},{'id': '359', 'type': 'string', 'children': [], 'value': '"This is possibly due to a BLASTN comparison "'},{'id': '360', 'type': 'string', 'children': [], 'value': '"being too distant for use."'},{'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': 'logger'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '366', 'type': 'argument_list', 'children': ['367']},{'id': '367', 'type': 'call', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'last_exception'},{'id': '369', 'type': 'argument_list', 'children': []},{'id': '370', 'type': 'if_statement', 'children': ['371', '375']},{'id': '371', 'type': 'not_operator', 'children': ['372']},{'id': '372', 'type': 'attribute', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'nocompress'},{'id': '375', 'type': 'block', 'children': ['376', '384']},{'id': '376', 'type': 'expression_statement', 'children': ['377']},{'id': '377', 'type': 'call', 'children': ['378', '381']},{'id': '378', 'type': 'attribute', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '381', 'type': 'argument_list', 'children': ['382', '383']},{'id': '382', 'type': 'string', 'children': [], 'value': '"Compressing/deleting %s"'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'blastdir'},{'id': '384', 'type': 'expression_statement', 'children': ['385']},{'id': '385', 'type': 'call', 'children': ['386', '387']},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'compress_delete_outdir'},{'id': '387', 'type': 'argument_list', 'children': ['388']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'blastdir'},{'id': '389', 'type': 'return_statement', 'children': ['390']},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'data'} | def unified_anib(infiles, org_lengths):
logger.info("Running %s", args.method)
blastdir = os.path.join(args.outdirname, ALIGNDIR[args.method])
logger.info("Writing BLAST output to %s", blastdir)
if not args.skip_blastn:
logger.info("Fragmenting input files, and writing to %s", args.outdirname)
fragfiles, fraglengths = anib.fragment_fasta_files(
infiles, blastdir, args.fragsize
)
with open(os.path.join(blastdir, "fraglengths.json"), "w") as outfile:
json.dump(fraglengths, outfile)
logger.info("Creating job dependency graph")
jobgraph = anib.make_job_graph(
infiles, fragfiles, anib.make_blastcmd_builder(args.method, blastdir)
)
if args.scheduler == "multiprocessing":
logger.info("Running jobs with multiprocessing")
logger.info("Running job dependency graph")
if args.workers is None:
logger.info("(using maximum number of available " + "worker threads)")
else:
logger.info("(using %d worker threads, if available)", args.workers)
cumval = run_mp.run_dependency_graph(
jobgraph, workers=args.workers, logger=logger
)
if 0 < cumval:
logger.warning(
"At least one BLAST run failed. " + "%s may fail.", args.method
)
else:
logger.info("All multiprocessing jobs complete.")
else:
run_sge.run_dependency_graph(jobgraph, logger=logger)
logger.info("Running jobs with SGE")
else:
if args.method == "ANIblastall":
with open(os.path.join(blastdir, "fraglengths.json"), "rU") as infile:
fraglengths = json.load(infile)
else:
fraglengths = None
logger.warning("Skipping BLASTN runs (as instructed)!")
logger.info("Processing pairwise %s BLAST output.", args.method)
try:
data = anib.process_blast(
blastdir, org_lengths, fraglengths=fraglengths, mode=args.method
)
except ZeroDivisionError:
logger.error("One or more BLAST output files has a problem.")
if not args.skip_blastn:
if 0 < cumval:
logger.error(
"This is possibly due to BLASTN run failure, "
+ "please investigate"
)
else:
logger.error(
"This is possibly due to a BLASTN comparison "
+ "being too distant for use."
)
logger.error(last_exception())
if not args.nocompress:
logger.info("Compressing/deleting %s", blastdir)
compress_delete_outdir(blastdir)
return data |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_deltadir'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'delta_dir'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '20', '35', '58', '267']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'deltafiles'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'pyani_files'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'get_input_files'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'delta_dir'},{'id': '19', 'type': 'string', 'children': [], 'value': '".filter"'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'ANIResults'},{'id': '25', 'type': 'argument_list', 'children': ['26', '34']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'org_lengths'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'string', 'children': [], 'value': '"ANIm"'},{'id': '35', 'type': 'for_statement', 'children': ['36', '39', '47']},{'id': '36', 'type': 'pattern_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'length'},{'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', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '57']},{'id': '50', 'type': 'subscript', 'children': ['51', '56']},{'id': '51', 'type': 'subscript', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'alignment_lengths'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '58', 'type': 'for_statement', 'children': ['59', '60', '61']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'deltafile'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'deltafiles'},{'id': '61', 'type': 'block', 'children': ['62', '92', '121', '150', '159', '182', '193', '204', '230', '239', '248', '257']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '67']},{'id': '64', 'type': 'pattern_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '67', 'type': 'call', 'children': ['68', '90']},{'id': '68', 'type': 'attribute', 'children': ['69', '89']},{'id': '69', 'type': 'subscript', 'children': ['70', '88']},{'id': '70', 'type': 'call', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'subscript', 'children': ['78', '86']},{'id': '78', 'type': 'call', 'children': ['79', '84']},{'id': '79', 'type': 'attribute', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'deltafile'},{'id': '86', 'type': 'unary_operator', 'children': ['87'], 'value': '-'},{'id': '87', 'type': 'integer', 'children': [], 'value': '1'},{'id': '88', 'type': 'integer', 'children': [], 'value': '0'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'string', 'children': [], 'value': '"_vs_"'},{'id': '92', 'type': 'if_statement', 'children': ['93', '103']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'not'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'org_lengths'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'block', 'children': ['104', '120']},{'id': '104', 'type': 'if_statement', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'logger'},{'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': 'logger'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'binary_operator', 'children': ['114', '117'], 'value': '+'},{'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '%'},{'id': '115', 'type': 'string', 'children': [], 'value': '"Query name %s not in input "'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '117', 'type': 'binary_operator', 'children': ['118', '119'], 'value': '%'},{'id': '118', 'type': 'string', 'children': [], 'value': '"sequence list, skipping %s"'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'deltafile'},{'id': '120', 'type': 'continue_statement', 'children': []},{'id': '121', 'type': 'if_statement', 'children': ['122', '132']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'not'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '131', 'type': 'argument_list', 'children': []},{'id': '132', 'type': 'block', 'children': ['133', '149']},{'id': '133', 'type': 'if_statement', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'logger'},{'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': 'logger'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'binary_operator', 'children': ['143', '146'], 'value': '+'},{'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '%'},{'id': '144', 'type': 'string', 'children': [], 'value': '"Subject name %s not in input "'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '%'},{'id': '147', 'type': 'string', 'children': [], 'value': '"sequence list, skipping %s"'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'deltafile'},{'id': '149', 'type': 'continue_statement', 'children': []},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '155']},{'id': '152', 'type': 'pattern_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'tot_length'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'tot_sim_error'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'parse_delta'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'deltafile'},{'id': '159', 'type': 'if_statement', 'children': ['160', '167']},{'id': '160', 'type': 'boolean_operator', 'children': ['161', '164'], 'value': 'and'},{'id': '161', 'type': 'comparison_operator', 'children': ['162', '163'], 'value': '=='},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'tot_length'},{'id': '163', 'type': 'integer', 'children': [], 'value': '0'},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': 'is'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '166', 'type': 'None', 'children': []},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'if_statement', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '+'},{'id': '178', 'type': 'string', 'children': [], 'value': '"Total alignment length reported in "'},{'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '%'},{'id': '180', 'type': 'string', 'children': [], 'value': '"%s is zero!"'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'deltafile'},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'query_cover'},{'id': '185', 'type': 'binary_operator', 'children': ['186', '190'], 'value': '/'},{'id': '186', 'type': 'call', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'tot_length'},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'sbjct_cover'},{'id': '196', 'type': 'binary_operator', 'children': ['197', '201'], 'value': '/'},{'id': '197', 'type': 'call', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '199', 'type': 'argument_list', 'children': ['200']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'tot_length'},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '204', 'type': 'try_statement', 'children': ['205', '217']},{'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': 'perc_id'},{'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '-'},{'id': '210', 'type': 'integer', 'children': [], 'value': '1'},{'id': '211', 'type': 'binary_operator', 'children': ['212', '216'], 'value': '/'},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'tot_sim_error'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'tot_length'},{'id': '217', 'type': 'except_clause', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'ZeroDivisionError'},{'id': '219', 'type': 'block', 'children': ['220', '224']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'perc_id'},{'id': '223', 'type': 'integer', 'children': [], 'value': '0'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'assignment', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'zero_error'},{'id': '229', 'type': 'True', 'children': []},{'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': 'results'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'add_tot_length'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237', '238']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'tot_length'},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'add_sim_errors'},{'id': '244', 'type': 'argument_list', 'children': ['245', '246', '247']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'tot_sim_error'},{'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': 'results'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'add_pid'},{'id': '253', 'type': 'argument_list', 'children': ['254', '255', '256']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'perc_id'},{'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': 'results'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'add_coverage'},{'id': '262', 'type': 'argument_list', 'children': ['263', '264', '265', '266']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'query_cover'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'sbjct_cover'},{'id': '267', 'type': 'return_statement', 'children': ['268']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'results'} | def process_deltadir(delta_dir, org_lengths, logger=None):
deltafiles = pyani_files.get_input_files(delta_dir, ".filter")
results = ANIResults(list(org_lengths.keys()), "ANIm")
for org, length in list(org_lengths.items()):
results.alignment_lengths[org][org] = length
for deltafile in deltafiles:
qname, sname = os.path.splitext(os.path.split(deltafile)[-1])[0].split("_vs_")
if qname not in list(org_lengths.keys()):
if logger:
logger.warning(
"Query name %s not in input " % qname
+ "sequence list, skipping %s" % deltafile
)
continue
if sname not in list(org_lengths.keys()):
if logger:
logger.warning(
"Subject name %s not in input " % sname
+ "sequence list, skipping %s" % deltafile
)
continue
tot_length, tot_sim_error = parse_delta(deltafile)
if tot_length == 0 and logger is not None:
if logger:
logger.warning(
"Total alignment length reported in " + "%s is zero!" % deltafile
)
query_cover = float(tot_length) / org_lengths[qname]
sbjct_cover = float(tot_length) / org_lengths[sname]
try:
perc_id = 1 - float(tot_sim_error) / tot_length
except ZeroDivisionError:
perc_id = 0
results.zero_error = True
results.add_tot_length(qname, sname, tot_length)
results.add_sim_errors(qname, sname, tot_sim_error)
results.add_pid(qname, sname, perc_id)
results.add_coverage(qname, sname, query_cover, sbjct_cover)
return results |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_contigs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'asm_uid'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'contig_uids'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'batchsize'},{'id': '8', 'type': 'integer', 'children': [], 'value': '10000'},{'id': '9', 'type': 'block', 'children': ['10', '18', '44', '56', '83', '107', '119', '140', '148', '332', '344', '355']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': '"Collecting contig data for %s"'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'asm_uid'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'asm_record'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'Entrez'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '25', 'type': 'argument_list', 'children': ['26', '41']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'entrez_retry'},{'id': '28', 'type': 'argument_list', 'children': ['29', '32', '35', '38']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'Entrez'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'esummary'},{'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '34', 'type': 'string', 'children': [], 'value': "'assembly'"},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'asm_uid'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'rettype'},{'id': '40', 'type': 'string', 'children': [], 'value': "'text'"},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'validate'},{'id': '43', 'type': 'False', 'children': []},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'asm_organism'},{'id': '47', 'type': 'subscript', 'children': ['48', '55']},{'id': '48', 'type': 'subscript', 'children': ['49', '54']},{'id': '49', 'type': 'subscript', 'children': ['50', '53']},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'asm_record'},{'id': '52', 'type': 'string', 'children': [], 'value': "'DocumentSummarySet'"},{'id': '53', 'type': 'string', 'children': [], 'value': "'DocumentSummary'"},{'id': '54', 'type': 'integer', 'children': [], 'value': '0'},{'id': '55', 'type': 'string', 'children': [], 'value': "'SpeciesName'"},{'id': '56', 'type': 'try_statement', 'children': ['57', '76']},{'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': 'asm_strain'},{'id': '61', 'type': 'subscript', 'children': ['62', '75']},{'id': '62', 'type': 'subscript', 'children': ['63', '74']},{'id': '63', 'type': 'subscript', 'children': ['64', '73']},{'id': '64', 'type': 'subscript', 'children': ['65', '72']},{'id': '65', 'type': 'subscript', 'children': ['66', '71']},{'id': '66', 'type': 'subscript', 'children': ['67', '70']},{'id': '67', 'type': 'subscript', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'asm_record'},{'id': '69', 'type': 'string', 'children': [], 'value': "'DocumentSummarySet'"},{'id': '70', 'type': 'string', 'children': [], 'value': "'DocumentSummary'"},{'id': '71', 'type': 'integer', 'children': [], 'value': '0'},{'id': '72', 'type': 'string', 'children': [], 'value': "'Biosource'"},{'id': '73', 'type': 'string', 'children': [], 'value': "'InfraspeciesList'"},{'id': '74', 'type': 'integer', 'children': [], 'value': '0'},{'id': '75', 'type': 'string', 'children': [], 'value': "'Sub_value'"},{'id': '76', 'type': 'except_clause', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'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': 'asm_strain'},{'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': 'outfilename'},{'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '%'},{'id': '87', 'type': 'string', 'children': [], 'value': '"%s.fasta"'},{'id': '88', 'type': 'call', 'children': ['89', '94']},{'id': '89', 'type': 'attribute', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '94', 'type': 'argument_list', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'outdirname'},{'id': '98', 'type': 'subscript', 'children': ['99', '106']},{'id': '99', 'type': 'subscript', 'children': ['100', '105']},{'id': '100', 'type': 'subscript', 'children': ['101', '104']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'asm_record'},{'id': '103', 'type': 'string', 'children': [], 'value': "'DocumentSummarySet'"},{'id': '104', 'type': 'string', 'children': [], 'value': "'DocumentSummary'"},{'id': '105', 'type': 'integer', 'children': [], 'value': '0'},{'id': '106', 'type': 'string', 'children': [], 'value': "'AssemblyAccession'"},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '112']},{'id': '109', 'type': 'pattern_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'genus'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'species'},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'asm_organism'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '116', 'type': 'argument_list', 'children': ['117', '118']},{'id': '117', 'type': 'string', 'children': [], 'value': "' '"},{'id': '118', 'type': 'integer', 'children': [], 'value': '1'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '124', 'type': 'argument_list', 'children': ['125', '126', '127']},{'id': '125', 'type': 'string', 'children': [], 'value': '"Downloading FASTA records for assembly %s (%s)"'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'asm_uid'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'string', 'children': [], 'value': "' '"},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'list', 'children': ['133', '138', '139'], 'value': "[genus[0] + '.', species, asm_strain]"},{'id': '133', 'type': 'binary_operator', 'children': ['134', '137'], 'value': '+'},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'genus'},{'id': '136', 'type': 'integer', 'children': [], 'value': '0'},{'id': '137', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'species'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'asm_strain'},{'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': 'tries'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '145', 'type': 'expression_list', 'children': ['146', '147']},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'False', 'children': []},{'id': '148', 'type': 'while_statement', 'children': ['149', '157']},{'id': '149', 'type': 'boolean_operator', 'children': ['150', '152'], 'value': 'and'},{'id': '150', 'type': 'not_operator', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': '<'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'retries'},{'id': '157', 'type': 'block', 'children': ['158', '162', '171']},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '161', 'type': 'list', 'children': [], 'value': '[]'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'query_uids'},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'string', 'children': [], 'value': "','"},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'contig_uids'},{'id': '171', 'type': 'try_statement', 'children': ['172', '305']},{'id': '172', 'type': 'block', 'children': ['173', '235', '239', '287']},{'id': '173', 'type': 'for_statement', 'children': ['174', '175', '184']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179', '183']},{'id': '178', 'type': 'integer', 'children': [], 'value': '0'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'contig_uids'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'batchsize'},{'id': '184', 'type': 'block', 'children': ['185', '196']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '190', 'type': 'argument_list', 'children': ['191', '192', '193']},{'id': '191', 'type': 'string', 'children': [], 'value': '"Batch: %d-%d"'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '193', 'type': 'binary_operator', 'children': ['194', '195'], 'value': '+'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'batchsize'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '209']},{'id': '206', 'type': 'attribute', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'SeqIO'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '209', 'type': 'argument_list', 'children': ['210', '234']},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'entrez_retry'},{'id': '212', 'type': 'argument_list', 'children': ['213', '216', '219', '222', '225', '228', '231']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'Entrez'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'efetch'},{'id': '216', 'type': 'keyword_argument', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '218', 'type': 'string', 'children': [], 'value': "'nucleotide'"},{'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'query_uids'},{'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'rettype'},{'id': '224', 'type': 'string', 'children': [], 'value': "'fasta'"},{'id': '225', 'type': 'keyword_argument', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'retmode'},{'id': '227', 'type': 'string', 'children': [], 'value': "'text'"},{'id': '228', 'type': 'keyword_argument', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'retstart'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'retmax'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'batchsize'},{'id': '234', 'type': 'string', 'children': [], 'value': "'fasta'"},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'augmented_assignment', 'children': ['237', '238'], 'value': '+='},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '238', 'type': 'integer', 'children': [], 'value': '1'},{'id': '239', 'type': 'if_statement', 'children': ['240', '249', '254']},{'id': '240', 'type': 'comparison_operator', 'children': ['241', '245'], 'value': '=='},{'id': '241', 'type': 'call', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '243', 'type': 'argument_list', 'children': ['244']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '245', 'type': 'call', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'contig_uids'},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'assignment', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '253', 'type': 'True', 'children': []},{'id': '254', 'type': 'else_clause', 'children': ['255']},{'id': '255', 'type': 'block', 'children': ['256', '271', '279']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'call', 'children': ['258', '261']},{'id': '258', 'type': 'attribute', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '261', 'type': 'argument_list', 'children': ['262', '263', '267']},{'id': '262', 'type': 'string', 'children': [], 'value': '"%d contigs expected, %d contigs returned"'},{'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': 'contig_uids'},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '276', 'type': 'argument_list', 'children': ['277', '278']},{'id': '277', 'type': 'string', 'children': [], 'value': '"FASTA download for assembly %s failed"'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'asm_uid'},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '284', 'type': 'argument_list', 'children': ['285', '286']},{'id': '285', 'type': 'string', 'children': [], 'value': '"try %d/20"'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'tries'},{'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': 'logger'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '292', 'type': 'argument_list', 'children': ['293', '294']},{'id': '293', 'type': 'string', 'children': [], 'value': '"Downloaded genome size: %d"'},{'id': '294', 'type': 'call', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'list_comprehension', 'children': ['298', '302']},{'id': '298', 'type': 'call', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '300', 'type': 'argument_list', 'children': ['301']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '302', 'type': 'for_in_clause', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '305', 'type': 'except_clause', 'children': ['306']},{'id': '306', 'type': 'block', 'children': ['307', '315', '324']},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'call', 'children': ['309', '312']},{'id': '309', 'type': 'attribute', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '312', 'type': 'argument_list', 'children': ['313', '314']},{'id': '313', 'type': 'string', 'children': [], 'value': '"FASTA download for assembly %s failed"'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'asm_uid'},{'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': 'logger'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '320', 'type': 'argument_list', 'children': ['321']},{'id': '321', 'type': 'call', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'last_exception'},{'id': '323', 'type': 'argument_list', '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': '"try %d/20"'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'tries'},{'id': '332', 'type': 'if_statement', 'children': ['333', '335']},{'id': '333', 'type': 'not_operator', 'children': ['334']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'success'},{'id': '335', 'type': 'block', 'children': ['336']},{'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': 'logger'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '341', 'type': 'argument_list', 'children': ['342', '343']},{'id': '342', 'type': 'string', 'children': [], 'value': '"Failed to download records for %s (continuing)"'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'asm_uid'},{'id': '344', 'type': 'expression_statement', 'children': ['345']},{'id': '345', 'type': 'assignment', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'retval'},{'id': '347', 'type': 'call', 'children': ['348', '351']},{'id': '348', 'type': 'attribute', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'SeqIO'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '351', 'type': 'argument_list', 'children': ['352', '353', '354']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'outfilename'},{'id': '354', 'type': 'string', 'children': [], 'value': "'fasta'"},{'id': '355', 'type': 'expression_statement', 'children': ['356']},{'id': '356', 'type': 'call', 'children': ['357', '360']},{'id': '357', 'type': 'attribute', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '360', 'type': 'argument_list', 'children': ['361', '362', '363']},{'id': '361', 'type': 'string', 'children': [], 'value': '"Wrote %d contigs to %s"'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'retval'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'outfilename'} | def write_contigs(asm_uid, contig_uids, batchsize=10000):
logger.info("Collecting contig data for %s", asm_uid)
asm_record = Entrez.read(
entrez_retry(
Entrez.esummary, db='assembly', id=asm_uid, rettype='text'),
validate=False)
asm_organism = asm_record['DocumentSummarySet']['DocumentSummary'][0][
'SpeciesName']
try:
asm_strain = asm_record['DocumentSummarySet']['DocumentSummary'][0][
'Biosource']['InfraspeciesList'][0]['Sub_value']
except KeyError:
asm_strain = ""
outfilename = "%s.fasta" % os.path.join(args.outdirname, asm_record[
'DocumentSummarySet']['DocumentSummary'][0]['AssemblyAccession'])
genus, species = asm_organism.split(' ', 1)
logger.info("Downloading FASTA records for assembly %s (%s)", asm_uid,
' '.join([genus[0] + '.', species, asm_strain]))
tries, success = 0, False
while not success and tries < args.retries:
records = []
query_uids = ','.join(contig_uids)
try:
for start in range(0, len(contig_uids), batchsize):
logger.info("Batch: %d-%d", start, start + batchsize)
records.extend(
list(
SeqIO.parse(
entrez_retry(
Entrez.efetch,
db='nucleotide',
id=query_uids,
rettype='fasta',
retmode='text',
retstart=start,
retmax=batchsize), 'fasta')))
tries += 1
if len(records) == len(contig_uids):
success = True
else:
logger.warning("%d contigs expected, %d contigs returned",
len(contig_uids), len(records))
logger.warning("FASTA download for assembly %s failed",
asm_uid)
logger.warning("try %d/20", tries)
logger.info("Downloaded genome size: %d",
sum([len(r) for r in records]))
except:
logger.warning("FASTA download for assembly %s failed", asm_uid)
logger.warning(last_exception())
logger.warning("try %d/20", tries)
if not success:
logger.error("Failed to download records for %s (continuing)", asm_uid)
retval = SeqIO.write(records, outfilename, 'fasta')
logger.info("Wrote %d contigs to %s", retval, outfilename) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'calculate_tetra_zscore'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '5', 'type': 'block', 'children': ['6', '34', '258', '262', '315', '319', '323', '442']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '9', 'type': 'tuple', 'children': ['10', '16', '22', '28']},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '34', 'type': 'for_statement', 'children': ['35', '36', '43']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'SeqIO'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'parse'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'filename'},{'id': '42', 'type': 'string', 'children': [], 'value': "'fasta'"},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'for_statement', 'children': ['45', '46', '71']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '46', 'type': 'list', 'children': ['47', '57'], 'value': '[str(rec.seq).upper(),\n str(rec.seq.reverse_complement()).upper()]'},{'id': '47', 'type': 'call', 'children': ['48', '56']},{'id': '48', 'type': 'attribute', 'children': ['49', '55']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '56', 'type': 'argument_list', 'children': []},{'id': '57', 'type': 'call', 'children': ['58', '70']},{'id': '58', 'type': 'attribute', 'children': ['59', '69']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '68']},{'id': '63', 'type': 'attribute', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'rec'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'reverse_complement'},{'id': '68', 'type': 'argument_list', 'children': []},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'block', 'children': ['72', '93', '172', '190', '206', '224', '242']},{'id': '72', 'type': 'for_statement', 'children': ['73', '74', '79']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '74', 'type': 'tuple', 'children': ['75', '76', '77', '78']},{'id': '75', 'type': 'string', 'children': [], 'value': "'G'"},{'id': '76', 'type': 'string', 'children': [], 'value': "'C'"},{'id': '77', 'type': 'string', 'children': [], 'value': "'T'"},{'id': '78', 'type': 'string', 'children': [], 'value': "'A'"},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'augmented_assignment', 'children': ['82', '87'], 'value': '+='},{'id': '82', 'type': 'subscript', 'children': ['83', '86']},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '85', 'type': 'integer', 'children': [], 'value': '0'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '93', 'type': 'for_statement', 'children': ['94', '95', '107']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'i'},{'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', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'subscript', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '103', 'type': 'slice', 'children': ['104', '105']},{'id': '104', 'type': 'colon', 'children': []},{'id': '105', 'type': 'unary_operator', 'children': ['106'], 'value': '-'},{'id': '106', 'type': 'integer', 'children': [], 'value': '4'},{'id': '107', 'type': 'block', 'children': ['108', '139', '150', '161']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '114']},{'id': '110', 'type': 'pattern_list', 'children': ['111', '112', '113']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'din'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'tri'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'tetra'},{'id': '114', 'type': 'expression_list', 'children': ['115', '123', '131']},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '117', 'type': 'slice', 'children': ['118', '119', '120']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '119', 'type': 'colon', 'children': []},{'id': '120', 'type': 'binary_operator', 'children': ['121', '122'], 'value': '+'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '122', 'type': 'integer', 'children': [], 'value': '2'},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '125', 'type': 'slice', 'children': ['126', '127', '128']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '127', 'type': 'colon', 'children': []},{'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '+'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '130', 'type': 'integer', 'children': [], 'value': '3'},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '133', 'type': 'slice', 'children': ['134', '135', '136']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '135', 'type': 'colon', 'children': []},{'id': '136', 'type': 'binary_operator', 'children': ['137', '138'], 'value': '+'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '138', 'type': 'integer', 'children': [], 'value': '4'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'augmented_assignment', 'children': ['141', '149'], 'value': '+='},{'id': '141', 'type': 'subscript', 'children': ['142', '145']},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '144', 'type': 'integer', 'children': [], 'value': '1'},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'din'},{'id': '149', 'type': 'integer', 'children': [], 'value': '1'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'augmented_assignment', 'children': ['152', '160'], 'value': '+='},{'id': '152', 'type': 'subscript', 'children': ['153', '156']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '155', 'type': 'integer', 'children': [], 'value': '2'},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'tri'},{'id': '160', 'type': 'integer', 'children': [], 'value': '1'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'augmented_assignment', 'children': ['163', '171'], 'value': '+='},{'id': '163', 'type': 'subscript', 'children': ['164', '167']},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '166', 'type': 'integer', 'children': [], 'value': '3'},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'tetra'},{'id': '171', 'type': 'integer', 'children': [], 'value': '1'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'augmented_assignment', 'children': ['174', '189'], 'value': '+='},{'id': '174', 'type': 'subscript', 'children': ['175', '178']},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '177', 'type': 'integer', 'children': [], 'value': '2'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'subscript', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '183', 'type': 'slice', 'children': ['184', '186', '187']},{'id': '184', 'type': 'unary_operator', 'children': ['185'], 'value': '-'},{'id': '185', 'type': 'integer', 'children': [], 'value': '4'},{'id': '186', 'type': 'colon', 'children': []},{'id': '187', 'type': 'unary_operator', 'children': ['188'], 'value': '-'},{'id': '188', 'type': 'integer', 'children': [], 'value': '1'},{'id': '189', 'type': 'integer', 'children': [], 'value': '1'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'augmented_assignment', 'children': ['192', '205'], 'value': '+='},{'id': '192', 'type': 'subscript', 'children': ['193', '196']},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '195', 'type': 'integer', 'children': [], 'value': '2'},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'subscript', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '201', 'type': 'slice', 'children': ['202', '204']},{'id': '202', 'type': 'unary_operator', 'children': ['203'], 'value': '-'},{'id': '203', 'type': 'integer', 'children': [], 'value': '3'},{'id': '204', 'type': 'colon', 'children': []},{'id': '205', 'type': 'integer', 'children': [], 'value': '1'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'augmented_assignment', 'children': ['208', '223'], 'value': '+='},{'id': '208', 'type': 'subscript', 'children': ['209', '212']},{'id': '209', 'type': 'subscript', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '211', 'type': 'integer', 'children': [], 'value': '1'},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'subscript', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '217', 'type': 'slice', 'children': ['218', '220', '221']},{'id': '218', 'type': 'unary_operator', 'children': ['219'], 'value': '-'},{'id': '219', 'type': 'integer', 'children': [], 'value': '4'},{'id': '220', 'type': 'colon', 'children': []},{'id': '221', 'type': 'unary_operator', 'children': ['222'], 'value': '-'},{'id': '222', 'type': 'integer', 'children': [], 'value': '2'},{'id': '223', 'type': 'integer', 'children': [], 'value': '1'},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'augmented_assignment', 'children': ['226', '241'], 'value': '+='},{'id': '226', 'type': 'subscript', 'children': ['227', '230']},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '229', 'type': 'integer', 'children': [], 'value': '1'},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '232', 'type': 'argument_list', 'children': ['233']},{'id': '233', 'type': 'subscript', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '235', 'type': 'slice', 'children': ['236', '238', '239']},{'id': '236', 'type': 'unary_operator', 'children': ['237'], 'value': '-'},{'id': '237', 'type': 'integer', 'children': [], 'value': '3'},{'id': '238', 'type': 'colon', 'children': []},{'id': '239', 'type': 'unary_operator', 'children': ['240'], 'value': '-'},{'id': '240', 'type': 'integer', 'children': [], 'value': '1'},{'id': '241', 'type': 'integer', 'children': [], 'value': '1'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'augmented_assignment', 'children': ['244', '257'], 'value': '+='},{'id': '244', 'type': 'subscript', 'children': ['245', '248']},{'id': '245', 'type': 'subscript', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '247', 'type': 'integer', 'children': [], 'value': '1'},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'subscript', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '253', 'type': 'slice', 'children': ['254', '256']},{'id': '254', 'type': 'unary_operator', 'children': ['255'], 'value': '-'},{'id': '255', 'type': 'integer', 'children': [], 'value': '2'},{'id': '256', 'type': 'colon', 'children': []},{'id': '257', 'type': 'integer', 'children': [], 'value': '1'},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'tetra_exp'},{'id': '261', 'type': 'dictionary', 'children': []},{'id': '262', 'type': 'for_statement', 'children': ['263', '264', '276']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '264', 'type': 'list_comprehension', 'children': ['265', '266', '271']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'tetn'},{'id': '266', 'type': 'for_in_clause', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'tetn'},{'id': '268', 'type': 'subscript', 'children': ['269', '270']},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '270', 'type': 'integer', 'children': [], 'value': '3'},{'id': '271', 'type': 'if_clause', 'children': ['272']},{'id': '272', 'type': 'call', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'tetra_clean'},{'id': '274', 'type': 'argument_list', 'children': ['275']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'tetn'},{'id': '276', 'type': 'block', 'children': ['277']},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '282']},{'id': '279', 'type': 'subscript', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'tetra_exp'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '282', 'type': 'binary_operator', 'children': ['283', '304', '305'], 'value': '/'},{'id': '283', 'type': 'binary_operator', 'children': ['284', '295'], 'value': '*'},{'id': '284', 'type': 'binary_operator', 'children': ['285', '286'], 'value': '*'},{'id': '285', 'type': 'float', 'children': [], 'value': '1.'},{'id': '286', 'type': 'subscript', 'children': ['287', '290']},{'id': '287', 'type': 'subscript', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '289', 'type': 'integer', 'children': [], 'value': '2'},{'id': '290', 'type': 'subscript', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '292', 'type': 'slice', 'children': ['293', '294']},{'id': '293', 'type': 'colon', 'children': []},{'id': '294', 'type': 'integer', 'children': [], 'value': '3'},{'id': '295', 'type': 'subscript', 'children': ['296', '299']},{'id': '296', 'type': 'subscript', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '298', 'type': 'integer', 'children': [], 'value': '2'},{'id': '299', 'type': 'subscript', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '301', 'type': 'slice', 'children': ['302', '303']},{'id': '302', 'type': 'integer', 'children': [], 'value': '1'},{'id': '303', 'type': 'colon', 'children': []},{'id': '304', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '305', 'type': 'subscript', 'children': ['306', '309']},{'id': '306', 'type': 'subscript', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '308', 'type': 'integer', 'children': [], 'value': '1'},{'id': '309', 'type': 'subscript', 'children': ['310', '311']},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '311', 'type': 'slice', 'children': ['312', '313', '314']},{'id': '312', 'type': 'integer', 'children': [], 'value': '1'},{'id': '313', 'type': 'colon', 'children': []},{'id': '314', 'type': 'integer', 'children': [], 'value': '3'},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'assignment', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'tetra_sd'},{'id': '318', 'type': 'dictionary', 'children': []},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'assignment', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'tetra_z'},{'id': '322', 'type': 'dictionary', 'children': []},{'id': '323', 'type': 'for_statement', 'children': ['324', '327', '335']},{'id': '324', 'type': 'pattern_list', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '327', 'type': 'call', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '329', 'type': 'argument_list', 'children': ['330']},{'id': '330', 'type': 'call', 'children': ['331', '334']},{'id': '331', 'type': 'attribute', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'tetra_exp'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '334', 'type': 'argument_list', 'children': []},{'id': '335', 'type': 'block', 'children': ['336', '349', '391']},{'id': '336', 'type': 'expression_statement', 'children': ['337']},{'id': '337', 'type': 'assignment', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'den'},{'id': '339', 'type': 'subscript', 'children': ['340', '343']},{'id': '340', 'type': 'subscript', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '342', 'type': 'integer', 'children': [], 'value': '1'},{'id': '343', 'type': 'subscript', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '345', 'type': 'slice', 'children': ['346', '347', '348']},{'id': '346', 'type': 'integer', 'children': [], 'value': '1'},{'id': '347', 'type': 'colon', 'children': []},{'id': '348', 'type': 'integer', 'children': [], 'value': '3'},{'id': '349', 'type': 'expression_statement', 'children': ['350']},{'id': '350', 'type': 'assignment', 'children': ['351', '354']},{'id': '351', 'type': 'subscript', 'children': ['352', '353']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'tetra_sd'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '354', 'type': 'call', 'children': ['355', '358']},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '358', 'type': 'argument_list', 'children': ['359']},{'id': '359', 'type': 'binary_operator', 'children': ['360', '387'], 'value': '/'},{'id': '360', 'type': 'binary_operator', 'children': ['361', '375'], 'value': '*'},{'id': '361', 'type': 'binary_operator', 'children': ['362', '363'], 'value': '*'},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '363', 'type': '()', 'children': ['364']},{'id': '364', 'type': 'binary_operator', 'children': ['365', '366'], 'value': '-'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'den'},{'id': '366', 'type': 'subscript', 'children': ['367', '370']},{'id': '367', 'type': 'subscript', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '369', 'type': 'integer', 'children': [], 'value': '2'},{'id': '370', 'type': 'subscript', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '372', 'type': 'slice', 'children': ['373', '374']},{'id': '373', 'type': 'colon', 'children': []},{'id': '374', 'type': 'integer', 'children': [], 'value': '3'},{'id': '375', 'type': '()', 'children': ['376']},{'id': '376', 'type': 'binary_operator', 'children': ['377', '378'], 'value': '-'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'den'},{'id': '378', 'type': 'subscript', 'children': ['379', '382']},{'id': '379', 'type': 'subscript', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '381', 'type': 'integer', 'children': [], 'value': '2'},{'id': '382', 'type': 'subscript', 'children': ['383', '384']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '384', 'type': 'slice', 'children': ['385', '386']},{'id': '385', 'type': 'integer', 'children': [], 'value': '1'},{'id': '386', 'type': 'colon', 'children': []},{'id': '387', 'type': '()', 'children': ['388']},{'id': '388', 'type': 'binary_operator', 'children': ['389', '390'], 'value': '*'},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'den'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'den'},{'id': '391', 'type': 'try_statement', 'children': ['392', '410']},{'id': '392', 'type': 'block', 'children': ['393']},{'id': '393', 'type': 'expression_statement', 'children': ['394']},{'id': '394', 'type': 'assignment', 'children': ['395', '398']},{'id': '395', 'type': 'subscript', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'tetra_z'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '398', 'type': 'binary_operator', 'children': ['399', '407'], 'value': '/'},{'id': '399', 'type': '()', 'children': ['400']},{'id': '400', 'type': 'binary_operator', 'children': ['401', '406'], 'value': '-'},{'id': '401', 'type': 'subscript', 'children': ['402', '405']},{'id': '402', 'type': 'subscript', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '404', 'type': 'integer', 'children': [], 'value': '3'},{'id': '405', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '407', 'type': 'subscript', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'tetra_sd'},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '410', 'type': 'except_clause', 'children': ['411', '412']},{'id': '411', 'type': 'identifier', 'children': [], 'value': 'ZeroDivisionError'},{'id': '412', 'type': 'block', 'children': ['413']},{'id': '413', 'type': 'expression_statement', 'children': ['414']},{'id': '414', 'type': 'assignment', 'children': ['415', '418']},{'id': '415', 'type': 'subscript', 'children': ['416', '417']},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'tetra_z'},{'id': '417', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '418', 'type': 'binary_operator', 'children': ['419', '420'], 'value': '/'},{'id': '419', 'type': 'integer', 'children': [], 'value': '1'},{'id': '420', 'type': '()', 'children': ['421']},{'id': '421', 'type': 'binary_operator', 'children': ['422', '432'], 'value': '*'},{'id': '422', 'type': 'subscript', 'children': ['423', '426']},{'id': '423', 'type': 'subscript', 'children': ['424', '425']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '425', 'type': 'integer', 'children': [], 'value': '1'},{'id': '426', 'type': 'subscript', 'children': ['427', '428']},{'id': '427', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '428', 'type': 'slice', 'children': ['429', '430', '431']},{'id': '429', 'type': 'integer', 'children': [], 'value': '1'},{'id': '430', 'type': 'colon', 'children': []},{'id': '431', 'type': 'integer', 'children': [], 'value': '3'},{'id': '432', 'type': 'subscript', 'children': ['433', '436']},{'id': '433', 'type': 'subscript', 'children': ['434', '435']},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'counts'},{'id': '435', 'type': 'integer', 'children': [], 'value': '1'},{'id': '436', 'type': 'subscript', 'children': ['437', '438']},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'tet'},{'id': '438', 'type': 'slice', 'children': ['439', '440', '441']},{'id': '439', 'type': 'integer', 'children': [], 'value': '1'},{'id': '440', 'type': 'colon', 'children': []},{'id': '441', 'type': 'integer', 'children': [], 'value': '3'},{'id': '442', 'type': 'return_statement', 'children': ['443']},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'tetra_z'} | def calculate_tetra_zscore(filename):
counts = (collections.defaultdict(int), collections.defaultdict(int),
collections.defaultdict(int), collections.defaultdict(int))
for rec in SeqIO.parse(filename, 'fasta'):
for seq in [str(rec.seq).upper(),
str(rec.seq.reverse_complement()).upper()]:
for base in ('G', 'C', 'T', 'A'):
counts[0][base] += seq.count(base)
for i in range(len(seq[:-4])):
din, tri, tetra = seq[i:i+2], seq[i:i+3], seq[i:i+4]
counts[1][str(din)] += 1
counts[2][str(tri)] += 1
counts[3][str(tetra)] += 1
counts[2][str(seq[-4:-1])] += 1
counts[2][str(seq[-3:])] += 1
counts[1][str(seq[-4:-2])] += 1
counts[1][str(seq[-3:-1])] += 1
counts[1][str(seq[-2:])] += 1
tetra_exp = {}
for tet in [tetn for tetn in counts[3] if tetra_clean(tetn)]:
tetra_exp[tet] = 1. * counts[2][tet[:3]] * counts[2][tet[1:]] / \
counts[1][tet[1:3]]
tetra_sd = {}
tetra_z = {}
for tet, exp in list(tetra_exp.items()):
den = counts[1][tet[1:3]]
tetra_sd[tet] = math.sqrt(exp * (den - counts[2][tet[:3]]) *
(den - counts[2][tet[1:]]) / (den * den))
try:
tetra_z[tet] = (counts[3][tet] - exp)/tetra_sd[tet]
except ZeroDivisionError:
tetra_z[tet] = 1 / (counts[1][tet[1:3]] * counts[1][tet[1:3]])
return tetra_z |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'calculate_correlations'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tetra_z'},{'id': '5', 'type': 'block', 'children': ['6', '17', '39', '253']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'orgs'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'tetra_z'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'correlations'},{'id': '20', 'type': 'call', 'children': ['21', '37']},{'id': '21', 'type': 'attribute', 'children': ['22', '36']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '26', 'type': 'argument_list', 'children': ['27', '30', '33']},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'orgs'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'orgs'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'fillna'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '39', 'type': 'for_statement', 'children': ['40', '43', '52']},{'id': '40', 'type': 'pattern_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'org1'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'orgs'},{'id': '48', 'type': 'slice', 'children': ['49', '50']},{'id': '49', 'type': 'colon', 'children': []},{'id': '50', 'type': 'unary_operator', 'children': ['51'], 'value': '-'},{'id': '51', 'type': 'integer', 'children': [], 'value': '1'},{'id': '52', 'type': 'block', 'children': ['53']},{'id': '53', 'type': 'for_statement', 'children': ['54', '55', '62']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'org2'},{'id': '55', 'type': 'subscript', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'orgs'},{'id': '57', 'type': 'slice', 'children': ['58', '61']},{'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '+'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '60', 'type': 'integer', 'children': [], 'value': '1'},{'id': '61', 'type': 'colon', 'children': []},{'id': '62', 'type': 'block', 'children': ['63', '85', '98', '120', '136', '162', '191', '219', '241']},{'id': '63', 'type': 'assert_statement', 'children': ['64']},{'id': '64', 'type': 'comparison_operator', 'children': ['65', '75'], 'value': '=='},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'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': 'tetra_z'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'org1'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '84']},{'id': '79', 'type': 'attribute', 'children': ['80', '83']},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'tetra_z'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'org2'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '84', 'type': 'argument_list', 'children': []},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'tets'},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '97']},{'id': '92', 'type': 'attribute', 'children': ['93', '96']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'tetra_z'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'org1'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '97', 'type': 'argument_list', 'children': []},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'zscores'},{'id': '101', 'type': 'list', 'children': ['102', '111'], 'value': '[[tetra_z[org1][t] for t in tets],\n [tetra_z[org2][t] for t in tets]]'},{'id': '102', 'type': 'list_comprehension', 'children': ['103', '108']},{'id': '103', 'type': 'subscript', 'children': ['104', '107']},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'tetra_z'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'org1'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '108', 'type': 'for_in_clause', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'tets'},{'id': '111', 'type': 'list_comprehension', 'children': ['112', '117']},{'id': '112', 'type': 'subscript', 'children': ['113', '116']},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'tetra_z'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'org2'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '117', 'type': 'for_in_clause', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'tets'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'zmeans'},{'id': '123', 'type': 'list_comprehension', 'children': ['124', '133']},{'id': '124', 'type': 'binary_operator', 'children': ['125', '129'], 'value': '/'},{'id': '125', 'type': 'call', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'zscore'},{'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': 'zscore'},{'id': '133', 'type': 'for_in_clause', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'zscore'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'zscores'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'zdiffs'},{'id': '139', 'type': 'list', 'children': ['140', '151'], 'value': '[[z - zmeans[0] for z in zscores[0]],\n [z - zmeans[1] for z in zscores[1]]]'},{'id': '140', 'type': 'list_comprehension', 'children': ['141', '146']},{'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '-'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'zmeans'},{'id': '145', 'type': 'integer', 'children': [], 'value': '0'},{'id': '146', 'type': 'for_in_clause', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'zscores'},{'id': '150', 'type': 'integer', 'children': [], 'value': '0'},{'id': '151', 'type': 'list_comprehension', 'children': ['152', '157']},{'id': '152', 'type': 'binary_operator', 'children': ['153', '154'], 'value': '-'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '154', 'type': 'subscript', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'zmeans'},{'id': '156', 'type': 'integer', 'children': [], 'value': '1'},{'id': '157', 'type': 'for_in_clause', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'zscores'},{'id': '161', 'type': 'integer', 'children': [], 'value': '1'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'diffprods'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'list_comprehension', 'children': ['169', '180']},{'id': '169', 'type': 'binary_operator', 'children': ['170', '175'], 'value': '*'},{'id': '170', 'type': 'subscript', 'children': ['171', '174']},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'zdiffs'},{'id': '173', 'type': 'integer', 'children': [], 'value': '0'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '175', 'type': 'subscript', 'children': ['176', '179']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'zdiffs'},{'id': '178', 'type': 'integer', 'children': [], 'value': '1'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '180', 'type': 'for_in_clause', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '182', 'type': 'call', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'zdiffs'},{'id': '190', 'type': 'integer', 'children': [], 'value': '0'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'zdiffs2'},{'id': '194', 'type': 'list', 'children': ['195', '207'], 'value': '[sum([z * z for z in zdiffs[0]]),\n sum([z * z for z in zdiffs[1]])]'},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'list_comprehension', 'children': ['199', '202']},{'id': '199', 'type': 'binary_operator', 'children': ['200', '201'], 'value': '*'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '202', 'type': 'for_in_clause', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '204', 'type': 'subscript', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'zdiffs'},{'id': '206', 'type': 'integer', 'children': [], 'value': '0'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'list_comprehension', 'children': ['211', '214']},{'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '*'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '214', 'type': 'for_in_clause', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'zdiffs'},{'id': '218', 'type': 'integer', 'children': [], 'value': '1'},{'id': '219', 'type': 'expression_statement', 'children': ['220']},{'id': '220', 'type': 'assignment', 'children': ['221', '226']},{'id': '221', 'type': 'subscript', 'children': ['222', '225']},{'id': '222', 'type': 'subscript', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'correlations'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'org1'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'org2'},{'id': '226', 'type': 'binary_operator', 'children': ['227', '228', '229'], 'value': '/'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'diffprods'},{'id': '228', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '229', 'type': 'call', 'children': ['230', '233']},{'id': '230', 'type': 'attribute', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'binary_operator', 'children': ['235', '238'], 'value': '*'},{'id': '235', 'type': 'subscript', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'zdiffs2'},{'id': '237', 'type': 'integer', 'children': [], 'value': '0'},{'id': '238', 'type': 'subscript', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'zdiffs2'},{'id': '240', 'type': 'integer', 'children': [], 'value': '1'},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '248']},{'id': '243', 'type': 'subscript', 'children': ['244', '247']},{'id': '244', 'type': 'subscript', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'correlations'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'org2'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'org1'},{'id': '248', 'type': 'subscript', 'children': ['249', '252']},{'id': '249', 'type': 'subscript', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'correlations'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'org1'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'org2'},{'id': '253', 'type': 'return_statement', 'children': ['254']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'correlations'} | def calculate_correlations(tetra_z):
orgs = sorted(tetra_z.keys())
correlations = pd.DataFrame(index=orgs, columns=orgs,
dtype=float).fillna(1.0)
for idx, org1 in enumerate(orgs[:-1]):
for org2 in orgs[idx+1:]:
assert sorted(tetra_z[org1].keys()) == sorted(tetra_z[org2].keys())
tets = sorted(tetra_z[org1].keys())
zscores = [[tetra_z[org1][t] for t in tets],
[tetra_z[org2][t] for t in tets]]
zmeans = [sum(zscore)/len(zscore) for zscore in zscores]
zdiffs = [[z - zmeans[0] for z in zscores[0]],
[z - zmeans[1] for z in zscores[1]]]
diffprods = sum([zdiffs[0][i] * zdiffs[1][i] for i in
range(len(zdiffs[0]))])
zdiffs2 = [sum([z * z for z in zdiffs[0]]),
sum([z * z for z in zdiffs[1]])]
correlations[org1][org2] = diffprods / \
math.sqrt(zdiffs2[0] * zdiffs2[1])
correlations[org2][org1] = correlations[org1][org2]
return correlations |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_blast'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'blast_dir'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'fraglengths'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '11', 'type': 'string', 'children': [], 'value': '"ANIb"'},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '14', 'type': 'float', 'children': [], 'value': '0.3'},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'coverage'},{'id': '17', 'type': 'float', 'children': [], 'value': '0.7'},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '32', '47', '70', '239']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'blastfiles'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'pyani_files'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_input_files'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'blast_dir'},{'id': '31', 'type': 'string', 'children': [], 'value': '".blast_tab"'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ANIResults'},{'id': '37', 'type': 'argument_list', 'children': ['38', '46']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '47', 'type': 'for_statement', 'children': ['48', '51', '59']},{'id': '48', 'type': 'pattern_list', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '69']},{'id': '62', 'type': 'subscript', 'children': ['63', '68']},{'id': '63', 'type': 'subscript', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'alignment_lengths'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'org'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '73']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'blastfile'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'blastfiles'},{'id': '73', 'type': 'block', 'children': ['74', '104', '133', '162', '173', '186', '200', '214', '230']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '79']},{'id': '76', 'type': 'pattern_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '79', 'type': 'call', 'children': ['80', '102']},{'id': '80', 'type': 'attribute', 'children': ['81', '101']},{'id': '81', 'type': 'subscript', 'children': ['82', '100']},{'id': '82', 'type': 'call', 'children': ['83', '88']},{'id': '83', 'type': 'attribute', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'splitext'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'subscript', 'children': ['90', '98']},{'id': '90', 'type': 'call', 'children': ['91', '96']},{'id': '91', 'type': 'attribute', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'blastfile'},{'id': '98', 'type': 'unary_operator', 'children': ['99'], 'value': '-'},{'id': '99', 'type': 'integer', 'children': [], 'value': '1'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'string', 'children': [], 'value': '"_vs_"'},{'id': '104', 'type': 'if_statement', 'children': ['105', '115']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'not'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '114', 'type': 'argument_list', 'children': []},{'id': '115', 'type': 'block', 'children': ['116', '132']},{'id': '116', 'type': 'if_statement', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '124']},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'binary_operator', 'children': ['126', '129'], 'value': '+'},{'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '%'},{'id': '127', 'type': 'string', 'children': [], 'value': '"Query name %s not in input "'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '%'},{'id': '130', 'type': 'string', 'children': [], 'value': '"sequence list, skipping %s"'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'blastfile'},{'id': '132', 'type': 'continue_statement', 'children': []},{'id': '133', 'type': 'if_statement', 'children': ['134', '144']},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': 'not'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '143', 'type': 'argument_list', 'children': []},{'id': '144', 'type': 'block', 'children': ['145', '161']},{'id': '145', 'type': 'if_statement', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'binary_operator', 'children': ['155', '158'], 'value': '+'},{'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '%'},{'id': '156', 'type': 'string', 'children': [], 'value': '"Subject name %s not in input "'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '%'},{'id': '159', 'type': 'string', 'children': [], 'value': '"sequence list, skipping %s"'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'blastfile'},{'id': '161', 'type': 'continue_statement', 'children': []},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'assignment', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'resultvals'},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'parse_blast_tab'},{'id': '167', 'type': 'argument_list', 'children': ['168', '169', '170', '171', '172']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'blastfile'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'fraglengths'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'identity'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'coverage'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'mode'},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'assignment', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'query_cover'},{'id': '176', 'type': 'binary_operator', 'children': ['177', '183'], 'value': '/'},{'id': '177', 'type': 'call', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '179', 'type': 'argument_list', 'children': ['180']},{'id': '180', 'type': 'subscript', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'resultvals'},{'id': '182', 'type': 'integer', 'children': [], 'value': '0'},{'id': '183', 'type': 'subscript', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'org_lengths'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'qname'},{'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': 'results'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'add_tot_length'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193', '194', '197']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '194', 'type': 'subscript', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'resultvals'},{'id': '196', 'type': 'integer', 'children': [], 'value': '0'},{'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'sym'},{'id': '199', 'type': 'False', 'children': []},{'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': 'results'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'add_sim_errors'},{'id': '205', 'type': 'argument_list', 'children': ['206', '207', '208', '211']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'resultvals'},{'id': '210', 'type': 'integer', 'children': [], 'value': '1'},{'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'sym'},{'id': '213', 'type': 'False', 'children': []},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'add_pid'},{'id': '219', 'type': 'argument_list', 'children': ['220', '221', '222', '227']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '222', 'type': 'binary_operator', 'children': ['223', '224'], 'value': '*'},{'id': '223', 'type': 'float', 'children': [], 'value': '0.01'},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'resultvals'},{'id': '226', 'type': 'integer', 'children': [], 'value': '2'},{'id': '227', 'type': 'keyword_argument', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'sym'},{'id': '229', 'type': 'False', 'children': []},{'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': 'results'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'add_coverage'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237', '238']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'qname'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'sname'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'query_cover'},{'id': '239', 'type': 'return_statement', 'children': ['240']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'results'} | def process_blast(
blast_dir,
org_lengths,
fraglengths=None,
mode="ANIb",
identity=0.3,
coverage=0.7,
logger=None,
):
blastfiles = pyani_files.get_input_files(blast_dir, ".blast_tab")
results = ANIResults(list(org_lengths.keys()), mode)
for org, length in list(org_lengths.items()):
results.alignment_lengths[org][org] = length
for blastfile in blastfiles:
qname, sname = os.path.splitext(os.path.split(blastfile)[-1])[0].split("_vs_")
if qname not in list(org_lengths.keys()):
if logger:
logger.warning(
"Query name %s not in input " % qname
+ "sequence list, skipping %s" % blastfile
)
continue
if sname not in list(org_lengths.keys()):
if logger:
logger.warning(
"Subject name %s not in input " % sname
+ "sequence list, skipping %s" % blastfile
)
continue
resultvals = parse_blast_tab(blastfile, fraglengths, identity, coverage, mode)
query_cover = float(resultvals[0]) / org_lengths[qname]
results.add_tot_length(qname, sname, resultvals[0], sym=False)
results.add_sim_errors(qname, sname, resultvals[1], sym=False)
results.add_pid(qname, sname, 0.01 * resultvals[2], sym=False)
results.add_coverage(qname, sname, query_cover)
return results |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_dependency_graph'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'jobgraph'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'jgprefix'},{'id': '10', 'type': 'string', 'children': [], 'value': '"ANIm_SGE_JG"'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sgegroupsize'},{'id': '13', 'type': 'integer', 'children': [], 'value': '10000'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sgeargs'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'block', 'children': ['18', '25', '29', '94', '103', '124', '131', '138', '153', '162', '169']},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'build_joblist'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'jobgraph'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'dep_count'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'if_statement', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '31', 'type': 'block', 'children': ['32', '39']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'string', 'children': [], 'value': '"Jobs to run with scheduler"'},{'id': '39', 'type': 'for_statement', 'children': ['40', '41', '42']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'id': '42', 'type': 'block', 'children': ['43', '60']},{'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': 'info'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'string', 'children': [], 'value': '"{0}: {1}"'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '53', 'type': 'argument_list', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'command'},{'id': '60', 'type': 'if_statement', 'children': ['61', '67']},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '67', 'type': 'block', 'children': ['68', '77']},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'augmented_assignment', 'children': ['70', '71'], 'value': '+='},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'dep_count'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '77', 'type': 'for_statement', 'children': ['78', '79', '82']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '%'},{'id': '90', 'type': 'string', 'children': [], 'value': '"\\t[^ depends on: %s]"'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'binary_operator', 'children': ['101', '102'], 'value': '%'},{'id': '101', 'type': 'string', 'children': [], 'value': '"There are %d job dependencies"'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'dep_count'},{'id': '103', 'type': 'if_statement', 'children': ['104', '107']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': '=='},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'dep_count'},{'id': '106', 'type': 'integer', 'children': [], 'value': '0'},{'id': '107', 'type': 'block', 'children': ['108', '115']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'string', 'children': [], 'value': '"Compiling jobs into JobGroups"'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'compile_jobgroups_from_joblist'},{'id': '120', 'type': 'argument_list', 'children': ['121', '122', '123']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'jgprefix'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'sgegroupsize'},{'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': 'logger'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'string', 'children': [], 'value': '"Running jobs with scheduler..."'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'string', 'children': [], 'value': '"Jobs passed to scheduler in order:"'},{'id': '138', 'type': 'for_statement', 'children': ['139', '140', '141']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'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': 'logger'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'binary_operator', 'children': ['149', '150'], 'value': '%'},{'id': '149', 'type': 'string', 'children': [], 'value': '"\\t%s"'},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'build_and_submit_jobs'},{'id': '156', 'type': 'argument_list', 'children': ['157', '160', '161']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'curdir'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'sgeargs'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'info'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'string', 'children': [], 'value': '"Waiting for SGE-submitted jobs to finish (polling)"'},{'id': '169', 'type': 'for_statement', 'children': ['170', '171', '172']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'joblist'},{'id': '172', 'type': 'block', 'children': ['173']},{'id': '173', 'type': 'expression_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'job'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'wait'},{'id': '178', 'type': 'argument_list', 'children': []} | def run_dependency_graph(jobgraph, logger=None, jgprefix="ANIm_SGE_JG",
sgegroupsize=10000, sgeargs=None):
joblist = build_joblist(jobgraph)
dep_count = 0
if logger:
logger.info("Jobs to run with scheduler")
for job in joblist:
logger.info("{0}: {1}".format(job.name, job.command))
if len(job.dependencies):
dep_count += len(job.dependencies)
for dep in job.dependencies:
logger.info("\t[^ depends on: %s]" % dep.name)
logger.info("There are %d job dependencies" % dep_count)
if dep_count == 0:
logger.info("Compiling jobs into JobGroups")
joblist = compile_jobgroups_from_joblist(joblist, jgprefix,
sgegroupsize)
logger.info("Running jobs with scheduler...")
logger.info("Jobs passed to scheduler in order:")
for job in joblist:
logger.info("\t%s" % job.name)
build_and_submit_jobs(os.curdir, joblist, sgeargs)
logger.info("Waiting for SGE-submitted jobs to finish (polling)")
for job in joblist:
job.wait() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'outputpairedstats'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'writemode'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'name1'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'n1'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'm1'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'se1'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'min1'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'max1'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'name2'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'n2'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'm2'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'se2'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'min2'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'max2'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'statname'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '21', 'type': 'block', 'children': ['22', '26', '43', '70', '81', '127', '323']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '25', 'type': 'string', 'children': [], 'value': "''"},{'id': '26', 'type': 'try_statement', 'children': ['27', '40']},{'id': '27', 'type': 'block', 'children': ['28', '34']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '39', 'type': 'integer', 'children': [], 'value': '0'},{'id': '40', 'type': 'except_clause', 'children': ['41']},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'pass_statement', 'children': []},{'id': '43', 'type': 'if_statement', 'children': ['44', '47', '52', '61']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': '<'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '46', 'type': 'float', 'children': [], 'value': '0.001'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '51', 'type': 'string', 'children': [], 'value': "' ***'"},{'id': '52', 'type': 'elif_clause', 'children': ['53', '56']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': '<'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '55', 'type': 'float', 'children': [], 'value': '0.01'},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '60', 'type': 'string', 'children': [], 'value': "' **'"},{'id': '61', 'type': 'elif_clause', 'children': ['62', '65']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': '<'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '64', 'type': 'float', 'children': [], 'value': '0.05'},{'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': 'suffix'},{'id': '69', 'type': 'string', 'children': [], 'value': "' *'"},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '73', 'type': 'list', 'children': ['74'], 'value': "[['Name','N','Mean','SD','Min','Max']]"},{'id': '74', 'type': 'list', 'children': ['75', '76', '77', '78', '79', '80'], 'value': "['Name','N','Mean','SD','Min','Max']"},{'id': '75', 'type': 'string', 'children': [], 'value': "'Name'"},{'id': '76', 'type': 'string', 'children': [], 'value': "'N'"},{'id': '77', 'type': 'string', 'children': [], 'value': "'Mean'"},{'id': '78', 'type': 'string', 'children': [], 'value': "'SD'"},{'id': '79', 'type': 'string', 'children': [], 'value': "'Min'"},{'id': '80', 'type': 'string', 'children': [], 'value': "'Max'"},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'lofl'},{'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '+'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'title'},{'id': '86', 'type': 'list', 'children': ['87', '107'], 'value': '[[name1,n1,round(m1,3),round(math.sqrt(se1),3),min1,max1],\n [name2,n2,round(m2,3),round(math.sqrt(se2),3),min2,max2]]'},{'id': '87', 'type': 'list', 'children': ['88', '89', '90', '95', '105', '106'], 'value': '[name1,n1,round(m1,3),round(math.sqrt(se1),3),min1,max1]'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'name1'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'n1'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'm1'},{'id': '94', 'type': 'integer', 'children': [], 'value': '3'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '97', 'type': 'argument_list', 'children': ['98', '104']},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'se1'},{'id': '104', 'type': 'integer', 'children': [], 'value': '3'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'min1'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'max1'},{'id': '107', 'type': 'list', 'children': ['108', '109', '110', '115', '125', '126'], 'value': '[name2,n2,round(m2,3),round(math.sqrt(se2),3),min2,max2]'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'name2'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'n2'},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'm2'},{'id': '114', 'type': 'integer', 'children': [], 'value': '3'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '117', 'type': 'argument_list', 'children': ['118', '124']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'math'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'sqrt'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'se2'},{'id': '124', 'type': 'integer', 'children': [], 'value': '3'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'min2'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'max2'},{'id': '127', 'type': 'if_statement', 'children': ['128', '141', '218']},{'id': '128', 'type': 'boolean_operator', 'children': ['129', '135'], 'value': 'or'},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '134'], 'value': '!='},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'StringType'},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '140'], 'value': '=='},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '140', 'type': 'integer', 'children': [], 'value': '0'},{'id': '141', 'type': 'block', 'children': ['142', '146', '151', '155', '162', '166', '197', '214']},{'id': '142', 'type': 'expression_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'statname'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '154', 'type': 'argument_list', 'children': []},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'pstat'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'printcc'},{'id': '160', 'type': 'argument_list', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'lofl'},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '165', 'type': 'argument_list', 'children': []},{'id': '166', 'type': 'try_statement', 'children': ['167', '194']},{'id': '167', 'type': 'block', 'children': ['168', '181']},{'id': '168', 'type': 'if_statement', 'children': ['169', '174']},{'id': '169', 'type': 'comparison_operator', 'children': ['170', '173'], 'value': '=='},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '173', 'type': 'tuple', 'children': []},{'id': '174', 'type': 'block', 'children': ['175']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'assignment', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '178', 'type': 'subscript', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '180', 'type': 'integer', 'children': [], 'value': '0'},{'id': '181', 'type': 'if_statement', 'children': ['182', '187']},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '186'], 'value': '=='},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '186', 'type': 'tuple', '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': 'prob'},{'id': '191', 'type': 'subscript', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '193', 'type': 'integer', 'children': [], 'value': '0'},{'id': '194', 'type': 'except_clause', 'children': ['195']},{'id': '195', 'type': 'block', 'children': ['196']},{'id': '196', 'type': 'pass_statement', 'children': []},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '200', 'type': 'argument_list', 'children': ['201', '202', '207', '208', '213']},{'id': '201', 'type': 'string', 'children': [], 'value': "'Test statistic = '"},{'id': '202', 'type': 'call', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '206', 'type': 'integer', 'children': [], 'value': '3'},{'id': '207', 'type': 'string', 'children': [], 'value': "' p = '"},{'id': '208', 'type': 'call', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '210', 'type': 'argument_list', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '212', 'type': 'integer', 'children': [], 'value': '3'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'call', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '217', 'type': 'argument_list', 'children': []},{'id': '218', 'type': 'else_clause', 'children': ['219']},{'id': '219', 'type': 'block', 'children': ['220', '228', '239', '245', '252', '260', '291', '317']},{'id': '220', 'type': 'expression_statement', 'children': ['221']},{'id': '221', 'type': 'assignment', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'writemode'},{'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': 'file'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'binary_operator', 'children': ['235', '238'], 'value': '+'},{'id': '235', 'type': 'binary_operator', 'children': ['236', '237'], 'value': '+'},{'id': '236', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'statname'},{'id': '238', 'type': 'string', 'children': [], 'value': "'\\n\\n'"},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '244', 'type': 'argument_list', 'children': []},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'writecc'},{'id': '248', 'type': 'argument_list', 'children': ['249', '250', '251']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'lofl'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '251', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '252', 'type': 'expression_statement', 'children': ['253']},{'id': '253', 'type': 'assignment', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '255', 'type': 'call', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '257', 'type': 'argument_list', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'fname'},{'id': '259', 'type': 'string', 'children': [], 'value': "'a'"},{'id': '260', 'type': 'try_statement', 'children': ['261', '288']},{'id': '261', 'type': 'block', 'children': ['262', '275']},{'id': '262', 'type': 'if_statement', 'children': ['263', '268']},{'id': '263', 'type': 'comparison_operator', 'children': ['264', '267'], 'value': '=='},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '267', 'type': 'tuple', 'children': []},{'id': '268', 'type': 'block', 'children': ['269']},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'assignment', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '272', 'type': 'subscript', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '274', 'type': 'integer', 'children': [], 'value': '0'},{'id': '275', 'type': 'if_statement', 'children': ['276', '281']},{'id': '276', 'type': 'comparison_operator', 'children': ['277', '280'], 'value': '=='},{'id': '277', 'type': 'attribute', 'children': ['278', '279']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '280', 'type': 'tuple', 'children': []},{'id': '281', 'type': 'block', 'children': ['282']},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'assignment', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '285', 'type': 'subscript', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '287', 'type': 'integer', 'children': [], 'value': '0'},{'id': '288', 'type': 'except_clause', 'children': ['289']},{'id': '289', 'type': 'block', 'children': ['290']},{'id': '290', 'type': 'pass_statement', 'children': []},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'call', 'children': ['293', '296']},{'id': '293', 'type': 'attribute', 'children': ['294', '295']},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '296', 'type': 'argument_list', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '301']},{'id': '298', 'type': 'attribute', 'children': ['299', '300']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'pstat'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'list2string'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'list', 'children': ['303', '304', '309', '310', '315', '316'], 'value': "['\\nTest statistic = ',round(stat,4),' p = ',round(prob,4),suffix,'\\n\\n']"},{'id': '303', 'type': 'string', 'children': [], 'value': "'\\nTest statistic = '"},{'id': '304', 'type': 'call', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '306', 'type': 'argument_list', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'stat'},{'id': '308', 'type': 'integer', 'children': [], 'value': '4'},{'id': '309', 'type': 'string', 'children': [], 'value': "' p = '"},{'id': '310', 'type': 'call', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'round'},{'id': '312', 'type': 'argument_list', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'prob'},{'id': '314', 'type': 'integer', 'children': [], 'value': '4'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '316', 'type': 'string', 'children': [], 'value': "'\\n\\n'"},{'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': 'file'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '322', 'type': 'argument_list', 'children': []},{'id': '323', 'type': 'return_statement', 'children': ['324']},{'id': '324', 'type': 'None', 'children': []} | def outputpairedstats(fname,writemode,name1,n1,m1,se1,min1,max1,name2,n2,m2,se2,min2,max2,statname,stat,prob):
suffix = ''
try:
x = prob.shape
prob = prob[0]
except:
pass
if prob < 0.001: suffix = ' ***'
elif prob < 0.01: suffix = ' **'
elif prob < 0.05: suffix = ' *'
title = [['Name','N','Mean','SD','Min','Max']]
lofl = title+[[name1,n1,round(m1,3),round(math.sqrt(se1),3),min1,max1],
[name2,n2,round(m2,3),round(math.sqrt(se2),3),min2,max2]]
if type(fname)!=StringType or len(fname)==0:
print()
print(statname)
print()
pstat.printcc(lofl)
print()
try:
if stat.shape == ():
stat = stat[0]
if prob.shape == ():
prob = prob[0]
except:
pass
print('Test statistic = ',round(stat,3),' p = ',round(prob,3),suffix)
print()
else:
file = open(fname,writemode)
file.write('\n'+statname+'\n\n')
file.close()
writecc(lofl,fname,'a')
file = open(fname,'a')
try:
if stat.shape == ():
stat = stat[0]
if prob.shape == ():
prob = prob[0]
except:
pass
file.write(pstat.list2string(['\nTest statistic = ',round(stat,4),' p = ',round(prob,4),suffix,'\n\n']))
file.close()
return None |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'GeneReader'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '7', 'type': 'string', 'children': [], 'value': "'gff'"},{'id': '8', 'type': 'block', 'children': ['9', '16', '45', '208', '212', '216']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'known_formats'},{'id': '12', 'type': 'tuple', 'children': ['13', '14', '15']},{'id': '13', 'type': 'string', 'children': [], 'value': "'gff'"},{'id': '14', 'type': 'string', 'children': [], 'value': "'gtf'"},{'id': '15', 'type': 'string', 'children': [], 'value': "'bed'"},{'id': '16', 'type': 'if_statement', 'children': ['17', '20']},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'not'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'known_formats'},{'id': '20', 'type': 'block', 'children': ['21', '40']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '24', 'type': 'argument_list', 'children': ['25', '35']},{'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '%'},{'id': '26', 'type': 'string', 'children': [], 'value': "'%s format not in %s'"},{'id': '27', 'type': 'tuple', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': '","'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'known_formats'},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'stderr'},{'id': '40', 'type': 'raise_statement', 'children': ['41']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': "'?'"},{'id': '45', 'type': 'if_statement', 'children': ['46', '49']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': '=='},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '48', 'type': 'string', 'children': [], 'value': "'bed'"},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '53', 'type': 'block', 'children': ['54', '66', '72', '81', '87', '93', '102', '111', '120', '143', '168', '172', '201']},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '57', 'type': 'call', 'children': ['58', '65']},{'id': '58', 'type': 'attribute', 'children': ['59', '64']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '65', 'type': 'argument_list', 'children': []},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'f'},{'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': 'chrom_start'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '80', 'type': 'integer', 'children': [], 'value': '1'},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '86', 'type': 'integer', 'children': [], 'value': '4'},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '92', 'type': 'integer', 'children': [], 'value': '5'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'cdsStart'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'subscript', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '101', 'type': 'integer', 'children': [], 'value': '6'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'cdsEnd'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '110', 'type': 'integer', 'children': [], 'value': '7'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'blockCount'},{'id': '114', 'type': 'call', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '119', 'type': 'integer', 'children': [], 'value': '9'},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'blockSizes'},{'id': '123', 'type': 'list_comprehension', 'children': ['124', '128']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '130', 'type': 'call', 'children': ['131', '141']},{'id': '131', 'type': 'attribute', 'children': ['132', '140']},{'id': '132', 'type': 'call', 'children': ['133', '138']},{'id': '133', 'type': 'attribute', 'children': ['134', '137']},{'id': '134', 'type': 'subscript', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '136', 'type': 'integer', 'children': [], 'value': '10'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'string', 'children': [], 'value': "','"},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'string', 'children': [], 'value': "','"},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'blockStarts'},{'id': '146', 'type': 'list_comprehension', 'children': ['147', '153']},{'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '+'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'chrom_start'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '153', 'type': 'for_in_clause', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '155', 'type': 'call', 'children': ['156', '166']},{'id': '156', 'type': 'attribute', 'children': ['157', '165']},{'id': '157', 'type': 'call', 'children': ['158', '163']},{'id': '158', 'type': 'attribute', 'children': ['159', '162']},{'id': '159', 'type': 'subscript', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '161', 'type': 'integer', 'children': [], 'value': '11'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'string', 'children': [], 'value': "','"},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'string', 'children': [], 'value': "','"},{'id': '168', 'type': 'expression_statement', 'children': ['169']},{'id': '169', 'type': 'assignment', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'gene_exons'},{'id': '171', 'type': 'list', 'children': [], 'value': '[]'},{'id': '172', 'type': 'for_statement', 'children': ['173', '176', '181']},{'id': '173', 'type': 'pattern_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '178', 'type': 'argument_list', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'blockStarts'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'blockSizes'},{'id': '181', 'type': 'block', 'children': ['182', '186', '192']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'exon_start'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'exon_end'},{'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '+'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'gene_exons'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'tuple', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'exon_start'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'exon_end'},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'yield', 'children': ['203']},{'id': '203', 'type': 'expression_list', 'children': ['204', '205', '206', '207']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'gene_exons'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'genelist'},{'id': '211', 'type': 'dictionary', 'children': []},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'grouplist'},{'id': '215', 'type': 'list', 'children': [], 'value': '[]'},{'id': '216', 'type': 'if_statement', 'children': ['217', '224']},{'id': '217', 'type': 'boolean_operator', 'children': ['218', '221'], 'value': 'or'},{'id': '218', 'type': 'comparison_operator', 'children': ['219', '220'], 'value': '=='},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '220', 'type': 'string', 'children': [], 'value': "'gff'"},{'id': '221', 'type': 'comparison_operator', 'children': ['222', '223'], 'value': '=='},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '223', 'type': 'string', 'children': [], 'value': "'gtf'"},{'id': '224', 'type': 'block', 'children': ['225', '348', '364']},{'id': '225', 'type': 'for_statement', 'children': ['226', '227', '228']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'fh'},{'id': '228', 'type': 'block', 'children': ['229', '247', '253', '264', '273', '279', '305', '317', '331', '335']},{'id': '229', 'type': 'if_statement', 'children': ['230', '238', '245']},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236']},{'id': '235', 'type': 'string', 'children': [], 'value': "'\n fields = line.strip().split('"},{'id': '236', 'type': 'ERROR', 'children': ['237']},{'id': '237', 'type': 'escape_sequence', 'children': [], 'value': '\\t'},{'id': '238', 'type': 'ERROR', 'children': ['239']},{'id': '239', 'type': 'comparison_operator', 'children': ['240', '244'], 'value': '<'},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '244', 'type': 'integer', 'children': [], 'value': '9'},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'continue_statement', 'children': []},{'id': '247', 'type': 'expression_statement', 'children': ['248']},{'id': '248', 'type': 'assignment', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '250', 'type': 'subscript', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '252', 'type': 'integer', 'children': [], 'value': '0'},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'assignment', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'ex_st'},{'id': '256', 'type': 'binary_operator', 'children': ['257', '263'], 'value': '-'},{'id': '257', 'type': 'call', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'subscript', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '262', 'type': 'integer', 'children': [], 'value': '3'},{'id': '263', 'type': 'integer', 'children': [], 'value': '1'},{'id': '264', 'type': 'expression_statement', 'children': ['265']},{'id': '265', 'type': 'assignment', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'ex_end'},{'id': '267', 'type': 'call', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'subscript', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '272', 'type': 'integer', 'children': [], 'value': '4'},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '276', 'type': 'subscript', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '278', 'type': 'integer', 'children': [], 'value': '6'},{'id': '279', 'type': 'if_statement', 'children': ['280', '283', '297']},{'id': '280', 'type': 'comparison_operator', 'children': ['281', '282'], 'value': '=='},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '282', 'type': 'string', 'children': [], 'value': "'gtf'"},{'id': '283', 'type': 'block', 'children': ['284']},{'id': '284', 'type': 'expression_statement', 'children': ['285']},{'id': '285', 'type': 'assignment', 'children': ['286', '287']},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '287', 'type': 'subscript', 'children': ['288', '296']},{'id': '288', 'type': 'call', 'children': ['289', '294']},{'id': '289', 'type': 'attribute', 'children': ['290', '293']},{'id': '290', 'type': 'subscript', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '292', 'type': 'integer', 'children': [], 'value': '8'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '294', 'type': 'argument_list', 'children': ['295']},{'id': '295', 'type': 'string', 'children': [], 'value': "';'"},{'id': '296', 'type': 'integer', 'children': [], 'value': '0'},{'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', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '302', 'type': 'subscript', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '304', 'type': 'integer', 'children': [], 'value': '8'},{'id': '305', 'type': 'if_statement', 'children': ['306', '309']},{'id': '306', 'type': 'comparison_operator', 'children': ['307', '308'], 'value': 'not'},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'grouplist'},{'id': '309', 'type': 'block', 'children': ['310']},{'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': 'grouplist'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '315', 'type': 'argument_list', 'children': ['316']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '317', 'type': 'if_statement', 'children': ['318', '321']},{'id': '318', 'type': 'comparison_operator', 'children': ['319', '320'], 'value': 'not'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'genelist'},{'id': '321', 'type': 'block', 'children': ['322']},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'assignment', 'children': ['324', '327']},{'id': '324', 'type': 'subscript', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'genelist'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '327', 'type': 'tuple', 'children': ['328', '329', '330']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '330', 'type': 'list', 'children': [], 'value': '[]'},{'id': '331', 'type': 'expression_statement', 'children': ['332']},{'id': '332', 'type': 'assignment', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'exons_i'},{'id': '334', 'type': 'integer', 'children': [], 'value': '2'},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'call', 'children': ['337', '344']},{'id': '337', 'type': 'attribute', 'children': ['338', '343']},{'id': '338', 'type': 'subscript', 'children': ['339', '342']},{'id': '339', 'type': 'subscript', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'genelist'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'exons_i'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '344', 'type': 'argument_list', 'children': ['345']},{'id': '345', 'type': 'tuple', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'ex_st'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'ex_end'},{'id': '348', 'type': 'expression_statement', 'children': ['349']},{'id': '349', 'type': 'assignment', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'sp'},{'id': '351', 'type': 'lambda', 'children': ['352', '355']},{'id': '352', 'type': 'lambda_parameters', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '355', 'type': 'call', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '357', 'type': 'argument_list', 'children': ['358', '361']},{'id': '358', 'type': 'subscript', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '360', 'type': 'integer', 'children': [], 'value': '0'},{'id': '361', 'type': 'subscript', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '363', 'type': 'integer', 'children': [], 'value': '0'},{'id': '364', 'type': 'for_statement', 'children': ['365', '366', '367']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'grouplist'},{'id': '367', 'type': 'block', 'children': ['368', '377', '384']},{'id': '368', 'type': 'expression_statement', 'children': ['369']},{'id': '369', 'type': 'assignment', 'children': ['370', '374']},{'id': '370', 'type': 'pattern_list', 'children': ['371', '372', '373']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'gene_exons'},{'id': '374', 'type': 'subscript', 'children': ['375', '376']},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'genelist'},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'gene'},{'id': '377', 'type': 'expression_statement', 'children': ['378']},{'id': '378', 'type': 'assignment', 'children': ['379', '380']},{'id': '379', 'type': 'identifier', 'children': [], 'value': 'gene_exons'},{'id': '380', 'type': 'call', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'bitset_union'},{'id': '382', 'type': 'argument_list', 'children': ['383']},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'gene_exons'},{'id': '384', 'type': 'expression_statement', 'children': ['385']},{'id': '385', 'type': 'yield', 'children': ['386']},{'id': '386', 'type': 'expression_list', 'children': ['387', '388', '389', '390']},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'gene_exons'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'gene'} | def GeneReader( fh, format='gff' ):
known_formats = ( 'gff', 'gtf', 'bed')
if format not in known_formats:
print('%s format not in %s' % (format, ",".join( known_formats )), file=sys.stderr)
raise Exception('?')
if format == 'bed':
for line in fh:
f = line.strip().split()
chrom = f[0]
chrom_start = int(f[1])
name = f[4]
strand = f[5]
cdsStart = int(f[6])
cdsEnd = int(f[7])
blockCount = int(f[9])
blockSizes = [ int(i) for i in f[10].strip(',').split(',') ]
blockStarts = [ chrom_start + int(i) for i in f[11].strip(',').split(',') ]
gene_exons = []
for base,offset in zip( blockStarts, blockSizes ):
exon_start = base
exon_end = base+offset
gene_exons.append( (exon_start, exon_end) )
yield chrom, strand, gene_exons, name
genelist = {}
grouplist = []
if format == 'gff' or format == 'gtf':
for line in fh:
if line.startswith('
fields = line.strip().split('\t')
if len( fields ) < 9: continue
chrom = fields[0]
ex_st = int( fields[3] ) - 1
ex_end = int( fields[4] )
strand = fields[6]
if format == 'gtf':
group = fields[8].split(';')[0]
else:
group = fields[8]
if group not in grouplist: grouplist.append( group )
if group not in genelist:
genelist[group] = (chrom, strand, [])
exons_i = 2
genelist[group][exons_i].append( ( ex_st, ex_end ) )
sp = lambda a,b: cmp( a[0], b[0] )
for gene in grouplist:
chrom, strand, gene_exons = genelist[ gene ]
gene_exons = bitset_union( gene_exons )
yield chrom, strand, gene_exons, gene |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_next_maf'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'species_to_lengths'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'parse_e_rows'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '21', '31', '37', '45', '57', '70', '101', '105', '417']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'alignment'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'Alignment'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'species_to_lengths'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'species_to_lengths'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'skip_blank'},{'id': '30', 'type': 'True', 'children': []},{'id': '31', 'type': 'if_statement', 'children': ['32', '34']},{'id': '32', 'type': 'not_operator', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'None', 'children': []},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'if_statement', 'children': ['46', '51']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '50'], 'value': '!='},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'string', 'children': [], 'value': "'a'"},{'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': 'Exception'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'string', 'children': [], 'value': '"Expected \'a ...\' line"'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'alignment'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'parse_attributes'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '67', 'type': 'slice', 'children': ['68', '69']},{'id': '68', 'type': 'integer', 'children': [], 'value': '1'},{'id': '69', 'type': 'colon', 'children': []},{'id': '70', 'type': 'if_statement', 'children': ['71', '76', '93']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'in'},{'id': '72', 'type': 'string', 'children': [], 'value': "'score'"},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'alignment'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '76', 'type': 'block', 'children': ['77', '87']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'alignment'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '82', 'type': 'subscript', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'alignment'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '86', 'type': 'string', 'children': [], 'value': "'score'"},{'id': '87', 'type': 'delete_statement', 'children': ['88']},{'id': '88', 'type': 'subscript', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'alignment'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'attributes'},{'id': '92', 'type': 'string', 'children': [], 'value': "'score'"},{'id': '93', 'type': 'else_clause', 'children': ['94']},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'alignment'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '100', 'type': 'integer', 'children': [], 'value': '0'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'last_component'},{'id': '104', 'type': 'None', 'children': []},{'id': '105', 'type': 'while_statement', 'children': ['106', '107']},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'block', 'children': ['108', '115', '126', '134', '142']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'readline'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '115', 'type': 'if_statement', 'children': ['116', '124']},{'id': '116', 'type': 'boolean_operator', 'children': ['117', '119'], 'value': 'or'},{'id': '117', 'type': 'not_operator', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'isspace'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'break_statement', 'children': []},{'id': '126', 'type': 'if_statement', 'children': ['127', '132']},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'isspace'},{'id': '131', 'type': 'argument_list', 'children': []},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'break_statement', 'children': []},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '137', 'type': 'call', 'children': ['138', '141']},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '141', 'type': 'argument_list', 'children': []},{'id': '142', 'type': 'if_statement', 'children': ['143', '148', '235', '347', '393']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '147'], 'value': '=='},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'string', 'children': [], 'value': "'s'"},{'id': '148', 'type': 'block', 'children': ['149', '155', '163', '174', '185', '193', '204', '224', '231']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'Component'},{'id': '154', 'type': 'argument_list', 'children': []},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '168', 'type': 'call', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '170', 'type': 'argument_list', 'children': ['171']},{'id': '171', 'type': 'subscript', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '173', 'type': 'integer', 'children': [], 'value': '2'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'subscript', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '184', 'type': 'integer', 'children': [], 'value': '3'},{'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': 'component'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '192', 'type': 'integer', 'children': [], 'value': '4'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'src_size'},{'id': '198', 'type': 'call', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '200', 'type': 'argument_list', 'children': ['201']},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '203', 'type': 'integer', 'children': [], 'value': '5'},{'id': '204', 'type': 'if_statement', 'children': ['205', '211']},{'id': '205', 'type': 'comparison_operator', 'children': ['206', '210'], 'value': '>'},{'id': '206', 'type': 'call', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '208', 'type': 'argument_list', 'children': ['209']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '210', 'type': 'integer', 'children': [], 'value': '6'},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '217', 'type': 'call', 'children': ['218', '223']},{'id': '218', 'type': 'attribute', 'children': ['219', '222']},{'id': '219', 'type': 'subscript', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '221', 'type': 'integer', 'children': [], 'value': '6'},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '223', 'type': 'argument_list', 'children': []},{'id': '224', 'type': 'expression_statement', 'children': ['225']},{'id': '225', 'type': 'call', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'alignment'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'add_component'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'assignment', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'last_component'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '235', 'type': 'elif_clause', 'children': ['236', '241']},{'id': '236', 'type': 'comparison_operator', 'children': ['237', '240'], 'value': '=='},{'id': '237', 'type': 'subscript', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '239', 'type': 'integer', 'children': [], 'value': '0'},{'id': '240', 'type': 'string', 'children': [], 'value': "'e'"},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'if_statement', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'parse_e_rows'},{'id': '244', 'type': 'block', 'children': ['245', '251', '257', '265', '276', '287', '295', '306', '312', '322', '330', '336', '343']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'Component'},{'id': '250', 'type': 'argument_list', 'children': []},{'id': '251', 'type': 'expression_statement', 'children': ['252']},{'id': '252', 'type': 'assignment', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '256', 'type': 'True', 'children': []},{'id': '257', 'type': 'expression_statement', 'children': ['258']},{'id': '258', 'type': 'assignment', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '262', 'type': 'subscript', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '264', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'component'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '270', 'type': 'call', 'children': ['271', '272']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '272', 'type': 'argument_list', 'children': ['273']},{'id': '273', 'type': 'subscript', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '275', 'type': 'integer', 'children': [], 'value': '2'},{'id': '276', 'type': 'expression_statement', 'children': ['277']},{'id': '277', 'type': 'assignment', 'children': ['278', '281']},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'size'},{'id': '281', 'type': 'call', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'subscript', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '286', 'type': 'integer', 'children': [], 'value': '3'},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'assignment', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '292', 'type': 'subscript', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '294', 'type': 'integer', 'children': [], 'value': '4'},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'src_size'},{'id': '300', 'type': 'call', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '302', 'type': 'argument_list', 'children': ['303']},{'id': '303', 'type': 'subscript', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '305', 'type': 'integer', 'children': [], 'value': '5'},{'id': '306', 'type': 'expression_statement', 'children': ['307']},{'id': '307', 'type': 'assignment', 'children': ['308', '311']},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '311', 'type': 'None', 'children': []},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'assignment', 'children': ['314', '315']},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'synteny'},{'id': '315', 'type': 'call', 'children': ['316', '321']},{'id': '316', 'type': 'attribute', 'children': ['317', '320']},{'id': '317', 'type': 'subscript', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '319', 'type': 'integer', 'children': [], 'value': '6'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '321', 'type': 'argument_list', 'children': []},{'id': '322', 'type': 'assert_statement', 'children': ['323', '329']},{'id': '323', 'type': 'comparison_operator', 'children': ['324', '328'], 'value': '=='},{'id': '324', 'type': 'call', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '326', 'type': 'argument_list', 'children': ['327']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'synteny'},{'id': '328', 'type': 'integer', 'children': [], 'value': '1'},{'id': '329', 'type': 'string', 'children': [], 'value': '"Synteny status in \'e\' rows should be denoted with a single character code"'},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'assignment', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'synteny_empty'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'synteny'},{'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': 'alignment'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'add_component'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '343', 'type': 'expression_statement', 'children': ['344']},{'id': '344', 'type': 'assignment', 'children': ['345', '346']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'last_component'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'component'},{'id': '347', 'type': 'elif_clause', 'children': ['348', '353']},{'id': '348', 'type': 'comparison_operator', 'children': ['349', '352'], 'value': '=='},{'id': '349', 'type': 'subscript', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '351', 'type': 'integer', 'children': [], 'value': '0'},{'id': '352', 'type': 'string', 'children': [], 'value': "'i'"},{'id': '353', 'type': 'block', 'children': ['354', '363', '378']},{'id': '354', 'type': 'assert_statement', 'children': ['355', '362']},{'id': '355', 'type': 'comparison_operator', 'children': ['356', '359'], 'value': '=='},{'id': '356', 'type': 'subscript', 'children': ['357', '358']},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '358', 'type': 'integer', 'children': [], 'value': '1'},{'id': '359', 'type': 'attribute', 'children': ['360', '361']},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'last_component'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '362', 'type': 'string', 'children': [], 'value': '"\'i\' row does not follow matching \'s\' row"'},{'id': '363', 'type': 'expression_statement', 'children': ['364']},{'id': '364', 'type': 'assignment', 'children': ['365', '368']},{'id': '365', 'type': 'attribute', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'last_component'},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'synteny_left'},{'id': '368', 'type': 'tuple', 'children': ['369', '372']},{'id': '369', 'type': 'subscript', 'children': ['370', '371']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '371', 'type': 'integer', 'children': [], 'value': '2'},{'id': '372', 'type': 'call', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '374', 'type': 'argument_list', 'children': ['375']},{'id': '375', 'type': 'subscript', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '377', 'type': 'integer', 'children': [], 'value': '3'},{'id': '378', 'type': 'expression_statement', 'children': ['379']},{'id': '379', 'type': 'assignment', 'children': ['380', '383']},{'id': '380', 'type': 'attribute', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'last_component'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'synteny_right'},{'id': '383', 'type': 'tuple', 'children': ['384', '387']},{'id': '384', 'type': 'subscript', 'children': ['385', '386']},{'id': '385', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '386', 'type': 'integer', 'children': [], 'value': '4'},{'id': '387', 'type': 'call', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '389', 'type': 'argument_list', 'children': ['390']},{'id': '390', 'type': 'subscript', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '392', 'type': 'integer', 'children': [], 'value': '5'},{'id': '393', 'type': 'elif_clause', 'children': ['394', '399']},{'id': '394', 'type': 'comparison_operator', 'children': ['395', '398'], 'value': '=='},{'id': '395', 'type': 'subscript', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '397', 'type': 'integer', 'children': [], 'value': '0'},{'id': '398', 'type': 'string', 'children': [], 'value': "'q'"},{'id': '399', 'type': 'block', 'children': ['400', '409']},{'id': '400', 'type': 'assert_statement', 'children': ['401', '408']},{'id': '401', 'type': 'comparison_operator', 'children': ['402', '405'], 'value': '=='},{'id': '402', 'type': 'subscript', 'children': ['403', '404']},{'id': '403', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '404', 'type': 'integer', 'children': [], 'value': '1'},{'id': '405', 'type': 'attribute', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'last_component'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '408', 'type': 'string', 'children': [], 'value': '"\'q\' row does not follow matching \'s\' row"'},{'id': '409', 'type': 'expression_statement', 'children': ['410']},{'id': '410', 'type': 'assignment', 'children': ['411', '414']},{'id': '411', 'type': 'attribute', 'children': ['412', '413']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'last_component'},{'id': '413', 'type': 'identifier', 'children': [], 'value': 'quality'},{'id': '414', 'type': 'subscript', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '416', 'type': 'integer', 'children': [], 'value': '2'},{'id': '417', 'type': 'return_statement', 'children': ['418']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'alignment'} | def read_next_maf( file, species_to_lengths=None, parse_e_rows=False ):
alignment = Alignment(species_to_lengths=species_to_lengths)
line = readline( file, skip_blank=True )
if not line: return None
fields = line.split()
if fields[0] != 'a': raise Exception("Expected 'a ...' line")
alignment.attributes = parse_attributes( fields[1:] )
if 'score' in alignment.attributes:
alignment.score = alignment.attributes['score']
del alignment.attributes['score']
else:
alignment.score = 0
last_component = None
while 1:
line = readline( file )
if not line or line.isspace(): break
if line.isspace(): break
fields = line.split()
if fields[0] == 's':
component = Component()
component.src = fields[1]
component.start = int( fields[2] )
component.size = int( fields[3] )
component.strand = fields[4]
component.src_size = int( fields[5] )
if len(fields) > 6: component.text = fields[6].strip()
alignment.add_component( component )
last_component = component
elif fields[0] == 'e':
if parse_e_rows:
component = Component()
component.empty = True
component.src = fields[1]
component.start = int( fields[2] )
component.size = int( fields[3] )
component.strand = fields[4]
component.src_size = int( fields[5] )
component.text = None
synteny = fields[6].strip()
assert len( synteny ) == 1, \
"Synteny status in 'e' rows should be denoted with a single character code"
component.synteny_empty = synteny
alignment.add_component( component )
last_component = component
elif fields[0] == 'i':
assert fields[1] == last_component.src, "'i' row does not follow matching 's' row"
last_component.synteny_left = ( fields[2], int( fields[3] ) )
last_component.synteny_right = ( fields[4], int( fields[5] ) )
elif fields[0] == 'q':
assert fields[1] == last_component.src, "'q' row does not follow matching 's' row"
last_component.quality = fields[2]
return alignment |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_record'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '6', 'type': 'block', 'children': ['7', '11', '52', '56', '62', '66', '429']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'temp_lines'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '14']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '14', 'type': 'block', 'children': ['15', '30', '45']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '18', 'type': 'call', 'children': ['19', '27']},{'id': '19', 'type': 'attribute', 'children': ['20', '26']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'rstrip'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': '"\\r\\n"'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'None', 'children': []},{'id': '29', 'type': 'integer', 'children': [], 'value': '1'},{'id': '30', 'type': 'if_statement', 'children': ['31', '37']},{'id': '31', 'type': 'comparison_operator', 'children': ['32', '36'], 'value': '=='},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '36', 'type': 'integer', 'children': [], 'value': '1'},{'id': '37', 'type': 'block', 'children': ['38']},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': '""'},{'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': 'temp_lines'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'temp_lines'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'motif'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'TransfacMotif'},{'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': 'current_line'},{'id': '65', 'type': 'integer', 'children': [], 'value': '0'},{'id': '66', 'type': 'while_statement', 'children': ['67', '68']},{'id': '67', 'type': 'integer', 'children': [], 'value': '1'},{'id': '68', 'type': 'block', 'children': ['69', '78', '86', '98', '106', '130', '173', '231', '292']},{'id': '69', 'type': 'if_statement', 'children': ['70', '76']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': '>='},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '76', 'type': 'block', 'children': ['77']},{'id': '77', 'type': 'break_statement', 'children': []},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '83']},{'id': '80', 'type': 'pattern_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '83', 'type': 'subscript', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '86', 'type': 'if_statement', 'children': ['87', '92']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'not'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'parse_actions'},{'id': '92', 'type': 'block', 'children': ['93', '97']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'augmented_assignment', 'children': ['95', '96'], 'value': '+='},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '96', 'type': 'integer', 'children': [], 'value': '1'},{'id': '97', 'type': 'continue_statement', 'children': []},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '101', 'type': 'subscript', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'parse_actions'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '106', 'type': 'if_statement', 'children': ['107', '112']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': '=='},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '110', 'type': 'integer', 'children': [], 'value': '0'},{'id': '111', 'type': 'string', 'children': [], 'value': '"store_single"'},{'id': '112', 'type': 'block', 'children': ['113', '119', '126']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '118', 'type': 'integer', 'children': [], 'value': '1'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '122', 'type': 'argument_list', 'children': ['123', '124', '125']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'motif'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'augmented_assignment', 'children': ['128', '129'], 'value': '+='},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '129', 'type': 'integer', 'children': [], 'value': '1'},{'id': '130', 'type': 'if_statement', 'children': ['131', '136']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '135'], 'value': '=='},{'id': '132', 'type': 'subscript', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '134', 'type': 'integer', 'children': [], 'value': '0'},{'id': '135', 'type': 'string', 'children': [], 'value': '"store_single_list"'},{'id': '136', 'type': 'block', 'children': ['137', '143', '158', '169']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '140', 'type': 'subscript', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '142', 'type': 'integer', 'children': [], 'value': '1'},{'id': '143', 'type': 'if_statement', 'children': ['144', '150']},{'id': '144', 'type': 'not_operator', 'children': ['145']},{'id': '145', 'type': 'call', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '147', 'type': 'argument_list', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'motif'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '154', 'type': 'argument_list', 'children': ['155', '156', '157']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'motif'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '157', 'type': 'list', 'children': [], 'value': '[]'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'call', 'children': ['160', '167']},{'id': '160', 'type': 'attribute', 'children': ['161', '166']},{'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': 'motif'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'augmented_assignment', 'children': ['171', '172'], 'value': '+='},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '172', 'type': 'integer', 'children': [], 'value': '1'},{'id': '173', 'type': 'if_statement', 'children': ['174', '179']},{'id': '174', 'type': 'comparison_operator', 'children': ['175', '178'], 'value': '=='},{'id': '175', 'type': 'subscript', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '177', 'type': 'integer', 'children': [], 'value': '0'},{'id': '178', 'type': 'string', 'children': [], 'value': '"store_single_key_value"'},{'id': '179', 'type': 'block', 'children': ['180', '186', '202', '217', '227']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '183', 'type': 'subscript', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '185', 'type': 'integer', 'children': [], 'value': '1'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '191']},{'id': '188', 'type': 'pattern_list', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '191', 'type': 'call', 'children': ['192', '199']},{'id': '192', 'type': 'attribute', 'children': ['193', '198']},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '197', 'type': 'argument_list', 'children': []},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '199', 'type': 'argument_list', 'children': ['200', '201']},{'id': '200', 'type': 'string', 'children': [], 'value': "'='"},{'id': '201', 'type': 'integer', 'children': [], 'value': '1'},{'id': '202', 'type': 'if_statement', 'children': ['203', '209']},{'id': '203', 'type': 'not_operator', 'children': ['204']},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '206', 'type': 'argument_list', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'motif'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '209', 'type': 'block', 'children': ['210']},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'call', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '213', 'type': 'argument_list', 'children': ['214', '215', '216']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'motif'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '216', 'type': 'dictionary', 'children': []},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '226']},{'id': '219', 'type': 'subscript', 'children': ['220', '225']},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '222', 'type': 'argument_list', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'motif'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'augmented_assignment', 'children': ['229', '230'], 'value': '+='},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '230', 'type': 'integer', 'children': [], 'value': '1'},{'id': '231', 'type': 'if_statement', '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': 'action'},{'id': '235', 'type': 'integer', 'children': [], 'value': '0'},{'id': '236', 'type': 'string', 'children': [], 'value': '"store_block"'},{'id': '237', 'type': 'block', 'children': ['238', '244', '248', '279']},{'id': '238', 'type': 'expression_statement', 'children': ['239']},{'id': '239', 'type': 'assignment', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '241', 'type': 'subscript', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '243', 'type': 'integer', 'children': [], 'value': '1'},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '247', 'type': 'list', 'children': [], 'value': '[]'},{'id': '248', 'type': 'while_statement', 'children': ['249', '263']},{'id': '249', 'type': 'boolean_operator', 'children': ['250', '256'], 'value': 'and'},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': '<'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '252', 'type': 'call', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '254', 'type': 'argument_list', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '256', 'type': 'comparison_operator', 'children': ['257', '262'], 'value': '=='},{'id': '257', 'type': 'subscript', 'children': ['258', '261']},{'id': '258', 'type': 'subscript', 'children': ['259', '260']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '261', 'type': 'integer', 'children': [], 'value': '0'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '263', 'type': 'block', 'children': ['264', '275']},{'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': 'value'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'subscript', 'children': ['271', '274']},{'id': '271', 'type': 'subscript', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '274', 'type': 'integer', 'children': [], 'value': '1'},{'id': '275', 'type': 'expression_statement', 'children': ['276']},{'id': '276', 'type': 'augmented_assignment', 'children': ['277', '278'], 'value': '+='},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '278', 'type': 'integer', 'children': [], 'value': '1'},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'call', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '282', 'type': 'argument_list', 'children': ['283', '284', '285']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'motif'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '285', 'type': 'call', 'children': ['286', '289']},{'id': '286', 'type': 'attribute', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '289', 'type': 'argument_list', 'children': ['290', '291']},{'id': '290', 'type': 'string', 'children': [], 'value': '"\\n"'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '292', 'type': 'if_statement', 'children': ['293', '298']},{'id': '293', 'type': 'comparison_operator', 'children': ['294', '297'], 'value': '=='},{'id': '294', 'type': 'subscript', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '296', 'type': 'integer', 'children': [], 'value': '0'},{'id': '297', 'type': 'string', 'children': [], 'value': '"store_matrix"'},{'id': '298', 'type': 'block', 'children': ['299', '307', '314', '318', '322', '326', '395', '410', '420']},{'id': '299', 'type': 'expression_statement', 'children': ['300']},{'id': '300', 'type': 'assignment', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'alphabet'},{'id': '302', 'type': 'call', 'children': ['303', '306']},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '306', 'type': 'argument_list', 'children': []},{'id': '307', 'type': 'expression_statement', 'children': ['308']},{'id': '308', 'type': 'assignment', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'alphabet_size'},{'id': '310', 'type': 'call', 'children': ['311', '312']},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '312', 'type': 'argument_list', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'alphabet'},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '317', 'type': 'list', 'children': [], 'value': '[]'},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'assignment', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '321', 'type': 'string', 'children': [], 'value': '""'},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'augmented_assignment', 'children': ['324', '325'], 'value': '+='},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '325', 'type': 'integer', 'children': [], 'value': '1'},{'id': '326', 'type': 'while_statement', 'children': ['327', '333']},{'id': '327', 'type': 'comparison_operator', 'children': ['328', '329'], 'value': '<'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '329', 'type': 'call', 'children': ['330', '331']},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '331', 'type': 'argument_list', 'children': ['332']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '333', 'type': 'block', 'children': ['334', '342', '351', '359', '377', '391']},{'id': '334', 'type': 'expression_statement', 'children': ['335']},{'id': '335', 'type': 'assignment', 'children': ['336', '339']},{'id': '336', 'type': 'pattern_list', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '339', 'type': 'subscript', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'lines'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '342', 'type': 'if_statement', 'children': ['343', '349']},{'id': '343', 'type': 'not_operator', 'children': ['344']},{'id': '344', 'type': 'call', 'children': ['345', '348']},{'id': '345', 'type': 'attribute', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '348', 'type': 'argument_list', 'children': []},{'id': '349', 'type': 'block', 'children': ['350']},{'id': '350', 'type': 'break_statement', 'children': []},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'assignment', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '354', 'type': 'call', 'children': ['355', '358']},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'rest'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '358', 'type': 'argument_list', 'children': []},{'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': 'rows'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '364', 'type': 'argument_list', 'children': ['365']},{'id': '365', 'type': 'list_comprehension', 'children': ['366', '370']},{'id': '366', 'type': 'call', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '368', 'type': 'argument_list', 'children': ['369']},{'id': '369', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '370', 'type': 'for_in_clause', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '372', 'type': 'subscript', 'children': ['373', '374']},{'id': '373', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '374', 'type': 'slice', 'children': ['375', '376']},{'id': '375', 'type': 'colon', 'children': []},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'alphabet_size'},{'id': '377', 'type': 'if_statement', 'children': ['378', '384']},{'id': '378', 'type': 'comparison_operator', 'children': ['379', '383'], 'value': '>'},{'id': '379', 'type': 'call', 'children': ['380', '381']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '381', 'type': 'argument_list', 'children': ['382']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'alphabet_size'},{'id': '384', 'type': 'block', 'children': ['385']},{'id': '385', 'type': 'expression_statement', 'children': ['386']},{'id': '386', 'type': 'augmented_assignment', 'children': ['387', '388'], 'value': '+='},{'id': '387', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '388', 'type': 'subscript', 'children': ['389', '390']},{'id': '389', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '390', 'type': 'identifier', 'children': [], 'value': 'alphabet_size'},{'id': '391', 'type': 'expression_statement', 'children': ['392']},{'id': '392', 'type': 'augmented_assignment', 'children': ['393', '394'], 'value': '+='},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'current_line'},{'id': '394', 'type': 'integer', 'children': [], 'value': '1'},{'id': '395', 'type': 'if_statement', 'children': ['396', '405']},{'id': '396', 'type': 'comparison_operator', 'children': ['397', '401'], 'value': '!='},{'id': '397', 'type': 'call', 'children': ['398', '399']},{'id': '398', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '399', 'type': 'argument_list', 'children': ['400']},{'id': '400', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '401', 'type': 'call', 'children': ['402', '403']},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '403', 'type': 'argument_list', 'children': ['404']},{'id': '404', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '405', 'type': 'block', 'children': ['406']},{'id': '406', 'type': 'expression_statement', 'children': ['407']},{'id': '407', 'type': 'assignment', 'children': ['408', '409']},{'id': '408', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '409', 'type': 'None', 'children': []},{'id': '410', 'type': 'expression_statement', 'children': ['411']},{'id': '411', 'type': 'assignment', 'children': ['412', '413']},{'id': '412', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '413', 'type': 'call', 'children': ['414', '417']},{'id': '414', 'type': 'attribute', 'children': ['415', '416']},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'FrequencyMatrix'},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'from_rows'},{'id': '417', 'type': 'argument_list', 'children': ['418', '419']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'alphabet'},{'id': '419', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '420', 'type': 'expression_statement', 'children': ['421']},{'id': '421', 'type': 'call', 'children': ['422', '423']},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '423', 'type': 'argument_list', 'children': ['424', '425', '428']},{'id': '424', 'type': 'identifier', 'children': [], 'value': 'motif'},{'id': '425', 'type': 'subscript', 'children': ['426', '427']},{'id': '426', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '427', 'type': 'integer', 'children': [], 'value': '1'},{'id': '428', 'type': 'identifier', 'children': [], 'value': 'matrix'},{'id': '429', 'type': 'if_statement', 'children': ['430', '441']},{'id': '430', 'type': 'boolean_operator', 'children': ['431', '438'], 'value': 'or'},{'id': '431', 'type': 'boolean_operator', 'children': ['432', '435'], 'value': 'or'},{'id': '432', 'type': 'attribute', 'children': ['433', '434']},{'id': '433', 'type': 'identifier', 'children': [], 'value': 'motif'},{'id': '434', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '435', 'type': 'attribute', 'children': ['436', '437']},{'id': '436', 'type': 'identifier', 'children': [], 'value': 'motif'},{'id': '437', 'type': 'identifier', 'children': [], 'value': 'accession'},{'id': '438', 'type': 'attribute', 'children': ['439', '440']},{'id': '439', 'type': 'identifier', 'children': [], 'value': 'motif'},{'id': '440', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '441', 'type': 'block', 'children': ['442']},{'id': '442', 'type': 'return_statement', 'children': ['443']},{'id': '443', 'type': 'identifier', 'children': [], 'value': 'motif'} | def parse_record( self, lines ):
temp_lines = []
for line in lines:
fields = line.rstrip( "\r\n" ).split( None, 1 )
if len( fields ) == 1:
fields.append( "" )
temp_lines.append( fields )
lines = temp_lines
motif = TransfacMotif()
current_line = 0
while 1:
if current_line >= len( lines ):
break
prefix, rest = lines[ current_line ]
if prefix not in self.parse_actions:
current_line += 1
continue
action = self.parse_actions[ prefix ]
if action[0] == "store_single":
key = action[1]
setattr( motif, key, rest )
current_line += 1
if action[0] == "store_single_list":
key = action[1]
if not getattr( motif, key ):
setattr( motif, key, [] )
getattr( motif, key ).append( rest )
current_line += 1
if action[0] == "store_single_key_value":
key = action[1]
k, v = rest.strip().split( '=', 1 )
if not getattr( motif, key ):
setattr( motif, key, {} )
getattr( motif, key )[k] = v
current_line += 1
if action[0] == "store_block":
key = action[1]
value = []
while current_line < len( lines ) and lines[ current_line ][0] == prefix:
value.append( lines[current_line][1] )
current_line += 1
setattr( motif, key, str.join( "\n", value ) )
if action[0] == "store_matrix":
alphabet = rest.split()
alphabet_size = len( alphabet )
rows = []
pattern = ""
current_line += 1
while current_line < len( lines ):
prefix, rest = lines[ current_line ]
if not prefix.isdigit():
break
values = rest.split()
rows.append( [ float(_) for _ in values[:alphabet_size] ] )
if len( values ) > alphabet_size:
pattern += values[alphabet_size]
current_line += 1
if len( pattern ) != len( rows ):
pattern = None
matrix = FrequencyMatrix.from_rows( alphabet, rows )
setattr( motif, action[1], matrix )
if motif.id or motif.accession or motif.name:
return motif |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'tile_interval'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref_src'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'seq_db'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '54', '60', '71', '85', '93', '97', '163', '167', '184', '373']},{'id': '13', 'type': 'assert_statement', 'children': ['14', '33']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '25'], 'value': '=='},{'id': '15', 'type': 'subscript', 'children': ['16', '24']},{'id': '16', 'type': 'call', 'children': ['17', '22']},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'subscript', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'subscript', 'children': ['26', '32']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ref_src'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '32', 'type': 'integer', 'children': [], 'value': '0'},{'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'},{'id': '34', 'type': 'string', 'children': [], 'value': '"%s != %s"'},{'id': '35', 'type': 'tuple', 'children': ['36', '46']},{'id': '36', 'type': 'subscript', 'children': ['37', '45']},{'id': '37', 'type': 'call', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'subscript', 'children': ['47', '53']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'ref_src'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'base_len'},{'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '-'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69', '70']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'ref_src'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'end'},{'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': 'blocks'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'keyword_argument', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '79', 'type': 'lambda', 'children': ['80', '82']},{'id': '80', 'type': 'lambda_parameters', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'score'},{'id': '85', 'type': 'expression_statement', 'children': ['86']},{'id': '86', 'type': 'assignment', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '88', 'type': 'binary_operator', 'children': ['89', '92'], 'value': '*'},{'id': '89', 'type': 'list', 'children': ['90'], 'value': '[ -1 ]'},{'id': '90', 'type': 'unary_operator', 'children': ['91'], 'value': '-'},{'id': '91', 'type': 'integer', 'children': [], 'value': '1'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'base_len'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ref_src_size'},{'id': '96', 'type': 'None', 'children': []},{'id': '97', 'type': 'for_statement', 'children': ['98', '101', '105']},{'id': '98', 'type': 'pattern_list', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '105', 'type': 'block', 'children': ['106', '115', '121', '127', '137', '147']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '109', 'type': 'call', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'get_component_by_src_start'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'ref_src'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'ref_src_size'},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'src_size'},{'id': '121', 'type': 'assert_statement', 'children': ['122']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '126'], 'value': '=='},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '126', 'type': 'string', 'children': [], 'value': '"+"'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'slice_start'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '132', 'type': 'argument_list', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'slice_end'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '147', 'type': 'for_statement', 'children': ['148', '149', '154']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '151', 'type': 'argument_list', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'slice_start'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'slice_end'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '162']},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '-'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'j'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'start'},{'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': 'tiled'},{'id': '166', 'type': 'list', 'children': [], 'value': '[]'},{'id': '167', 'type': 'for_statement', 'children': ['168', '169', '176']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '169', 'type': 'call', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'tiled'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'list', 'children': [], 'value': '[]'},{'id': '184', 'type': 'for_statement', 'children': ['185', '189', '193']},{'id': '185', 'type': 'pattern_list', 'children': ['186', '187', '188']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'ss'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'ee'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'intervals_from_mask'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '193', 'type': 'block', 'children': ['194']},{'id': '194', 'type': 'if_statement', 'children': ['195', '198', '271']},{'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': '<'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '197', 'type': 'integer', 'children': [], 'value': '0'},{'id': '198', 'type': 'block', 'children': ['199', '251']},{'id': '199', 'type': 'if_statement', 'children': ['200', '201', '235']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'seq_db'},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '209']},{'id': '204', 'type': 'attribute', 'children': ['205', '208']},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'tiled'},{'id': '207', 'type': 'integer', 'children': [], 'value': '0'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '228']},{'id': '211', 'type': 'attribute', 'children': ['212', '227']},{'id': '212', 'type': 'call', 'children': ['213', '220']},{'id': '213', 'type': 'attribute', 'children': ['214', '219']},{'id': '214', 'type': 'attribute', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'bx'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'nib'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'NibFile'},{'id': '220', 'type': 'argument_list', 'children': ['221']},{'id': '221', 'type': 'call', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '223', 'type': 'argument_list', 'children': ['224']},{'id': '224', 'type': 'subscript', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'seq_db'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'ref_src'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '228', 'type': 'argument_list', 'children': ['229', '232']},{'id': '229', 'type': 'binary_operator', 'children': ['230', '231'], 'value': '+'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'ss'},{'id': '232', 'type': 'binary_operator', 'children': ['233', '234'], 'value': '-'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'ee'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'ss'},{'id': '235', 'type': 'else_clause', 'children': ['236']},{'id': '236', 'type': 'block', 'children': ['237']},{'id': '237', 'type': 'expression_statement', 'children': ['238']},{'id': '238', 'type': 'call', 'children': ['239', '244']},{'id': '239', 'type': 'attribute', 'children': ['240', '243']},{'id': '240', 'type': 'subscript', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'tiled'},{'id': '242', 'type': 'integer', 'children': [], 'value': '0'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '244', 'type': 'argument_list', 'children': ['245']},{'id': '245', 'type': 'binary_operator', 'children': ['246', '247'], 'value': '*'},{'id': '246', 'type': 'string', 'children': [], 'value': '"N"'},{'id': '247', 'type': '()', 'children': ['248']},{'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '-'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'ee'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'ss'},{'id': '251', 'type': 'for_statement', 'children': ['252', '253', '258']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '253', 'type': 'subscript', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'tiled'},{'id': '255', 'type': 'slice', 'children': ['256', '257']},{'id': '256', 'type': 'integer', 'children': [], 'value': '1'},{'id': '257', 'type': 'colon', 'children': []},{'id': '258', 'type': 'block', 'children': ['259']},{'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': 'row'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'binary_operator', 'children': ['266', '267'], 'value': '*'},{'id': '266', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '267', 'type': '()', 'children': ['268']},{'id': '268', 'type': 'binary_operator', 'children': ['269', '270'], 'value': '-'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'ee'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'ss'},{'id': '271', 'type': 'else_clause', 'children': ['272']},{'id': '272', 'type': 'block', 'children': ['273', '279', '285', '291', '300', '311', '320', '326']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'assignment', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'slice_start'},{'id': '276', 'type': 'binary_operator', 'children': ['277', '278'], 'value': '+'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'ss'},{'id': '279', 'type': 'expression_statement', 'children': ['280']},{'id': '280', 'type': 'assignment', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'slice_end'},{'id': '282', 'type': 'binary_operator', 'children': ['283', '284'], 'value': '+'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'ee'},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '288', 'type': 'subscript', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'blocks'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '291', 'type': 'expression_statement', 'children': ['292']},{'id': '292', 'type': 'assignment', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'get_component_by_src_start'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'ref_src'},{'id': '300', 'type': 'expression_statement', 'children': ['301']},{'id': '301', 'type': 'assignment', 'children': ['302', '303']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'sliced'},{'id': '303', 'type': 'call', 'children': ['304', '307']},{'id': '304', 'type': 'attribute', 'children': ['305', '306']},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'block'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'slice_by_component'},{'id': '307', 'type': 'argument_list', 'children': ['308', '309', '310']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'ref'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'slice_start'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'slice_end'},{'id': '311', 'type': 'expression_statement', 'children': ['312']},{'id': '312', 'type': 'assignment', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'sliced'},{'id': '314', 'type': 'call', 'children': ['315', '318']},{'id': '315', 'type': 'attribute', 'children': ['316', '317']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'sliced'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'limit_to_species'},{'id': '318', 'type': 'argument_list', 'children': ['319']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '320', 'type': 'expression_statement', 'children': ['321']},{'id': '321', 'type': 'call', 'children': ['322', '325']},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'sliced'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'remove_all_gap_columns'},{'id': '325', 'type': 'argument_list', 'children': []},{'id': '326', 'type': 'for_statement', 'children': ['327', '330', '334']},{'id': '327', 'type': 'pattern_list', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '330', 'type': 'call', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '332', 'type': 'argument_list', 'children': ['333']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'sources'},{'id': '334', 'type': 'block', 'children': ['335', '344']},{'id': '335', 'type': 'expression_statement', 'children': ['336']},{'id': '336', 'type': 'assignment', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'comp'},{'id': '338', 'type': 'call', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'sliced'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'get_component_by_src_start'},{'id': '342', 'type': 'argument_list', 'children': ['343']},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'src'},{'id': '344', 'type': 'if_statement', 'children': ['345', '346', '358']},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'comp'},{'id': '346', 'type': 'block', 'children': ['347']},{'id': '347', 'type': 'expression_statement', 'children': ['348']},{'id': '348', 'type': 'call', 'children': ['349', '354']},{'id': '349', 'type': 'attribute', 'children': ['350', '353']},{'id': '350', 'type': 'subscript', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'tiled'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '354', 'type': 'argument_list', 'children': ['355']},{'id': '355', 'type': 'attribute', 'children': ['356', '357']},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'comp'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '358', 'type': 'else_clause', 'children': ['359']},{'id': '359', 'type': 'block', 'children': ['360']},{'id': '360', 'type': 'expression_statement', 'children': ['361']},{'id': '361', 'type': 'call', 'children': ['362', '367']},{'id': '362', 'type': 'attribute', 'children': ['363', '366']},{'id': '363', 'type': 'subscript', 'children': ['364', '365']},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'tiled'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '367', 'type': 'argument_list', 'children': ['368']},{'id': '368', 'type': 'binary_operator', 'children': ['369', '370'], 'value': '*'},{'id': '369', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '370', 'type': 'attribute', 'children': ['371', '372']},{'id': '371', 'type': 'identifier', 'children': [], 'value': 'sliced'},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'text_size'},{'id': '373', 'type': 'return_statement', 'children': ['374']},{'id': '374', 'type': 'list_comprehension', 'children': ['375', '381']},{'id': '375', 'type': 'call', 'children': ['376', '379']},{'id': '376', 'type': 'attribute', 'children': ['377', '378']},{'id': '377', 'type': 'string', 'children': [], 'value': '""'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '379', 'type': 'argument_list', 'children': ['380']},{'id': '380', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '381', 'type': 'for_in_clause', 'children': ['382', '383']},{'id': '382', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'tiled'} | def tile_interval( sources, index, ref_src, start, end, seq_db=None ):
assert sources[0].split('.')[0] == ref_src.split('.')[0], \
"%s != %s" % ( sources[0].split('.')[0], ref_src.split('.')[0] )
base_len = end - start
blocks = index.get( ref_src, start, end )
blocks.sort(key=lambda t: t.score)
mask = [ -1 ] * base_len
ref_src_size = None
for i, block in enumerate( blocks ):
ref = block.get_component_by_src_start( ref_src )
ref_src_size = ref.src_size
assert ref.strand == "+"
slice_start = max( start, ref.start )
slice_end = min( end, ref.end )
for j in range( slice_start, slice_end ):
mask[j-start] = i
tiled = []
for i in range( len( sources ) ):
tiled.append( [] )
for ss, ee, index in intervals_from_mask( mask ):
if index < 0:
if seq_db:
tiled[0].append( bx.seq.nib.NibFile( open( seq_db[ ref_src ] ) ).get( start+ss, ee-ss ) )
else:
tiled[0].append( "N" * (ee-ss) )
for row in tiled[1:]:
row.append( "-" * ( ee - ss ) )
else:
slice_start = start + ss
slice_end = start + ee
block = blocks[index]
ref = block.get_component_by_src_start( ref_src )
sliced = block.slice_by_component( ref, slice_start, slice_end )
sliced = sliced.limit_to_species( sources )
sliced.remove_all_gap_columns()
for i, src in enumerate( sources ):
comp = sliced.get_component_by_src_start( src )
if comp:
tiled[i].append( comp.text )
else:
tiled[i].append( "-" * sliced.text_size )
return [ "".join( t ) for t in tiled ] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'binned_bitsets_proximity'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'chrom_col'},{'id': '7', 'type': 'integer', 'children': [], 'value': '0'},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'start_col'},{'id': '10', 'type': 'integer', 'children': [], 'value': '1'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'end_col'},{'id': '13', 'type': 'integer', 'children': [], 'value': '2'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'strand_col'},{'id': '16', 'type': 'integer', 'children': [], 'value': '5'},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'upstream'},{'id': '19', 'type': 'integer', 'children': [], 'value': '0'},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'downstream'},{'id': '22', 'type': 'integer', 'children': [], 'value': '0'},{'id': '23', 'type': 'block', 'children': ['24', '28', '32', '38', '209']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'last_chrom'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'last_bitset'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'bitsets'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '37', 'type': 'argument_list', 'children': []},{'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '41', 'type': 'block', 'children': ['42', '77', '83', '112', '130', '161', '192']},{'id': '42', 'type': 'if_statement', 'children': ['43', '46', '65']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '46', 'type': 'ERROR', 'children': ['47', '48', '49', '56', '57']},{'id': '47', 'type': 'ERROR', 'children': []},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '49', 'type': 'ERROR', 'children': ['50', '55']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '56', 'type': 'string', 'children': [], 'value': '"+"'},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '62'], 'value': '>='},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '+'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'strand_col'},{'id': '64', 'type': 'integer', 'children': [], 'value': '1'},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'if_statement', 'children': ['67', '72']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '71'], 'value': '=='},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'strand_col'},{'id': '71', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '76', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'chrom_col'},{'id': '83', 'type': 'if_statement', 'children': ['84', '87']},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '!='},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'last_chrom'},{'id': '87', 'type': 'block', 'children': ['88', '102', '106']},{'id': '88', 'type': 'if_statement', 'children': ['89', '92']},{'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'not'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'bitsets'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '98']},{'id': '95', 'type': 'subscript', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'bitsets'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'BinnedBitSet'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'MAX'},{'id': '102', 'type': 'expression_statement', 'children': ['103']},{'id': '103', 'type': 'assignment', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'last_chrom'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'last_bitset'},{'id': '109', 'type': 'subscript', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'bitsets'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'chrom'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '117']},{'id': '114', 'type': 'pattern_list', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '117', 'type': 'expression_list', 'children': ['118', '124']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'start_col'},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'end_col'},{'id': '130', 'type': 'if_statement', 'children': ['131', '134']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': '=='},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '133', 'type': 'string', 'children': [], 'value': '"+"'},{'id': '134', 'type': 'block', 'children': ['135', '148']},{'id': '135', 'type': 'if_statement', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'upstream'},{'id': '137', 'type': 'block', 'children': ['138']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'integer', 'children': [], 'value': '0'},{'id': '145', 'type': 'binary_operator', 'children': ['146', '147'], 'value': '-'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'upstream'},{'id': '148', 'type': 'if_statement', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'downstream'},{'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': 'end'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'MAX'},{'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '+'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'downstream'},{'id': '161', 'type': 'if_statement', 'children': ['162', '165']},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': '=='},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'strand'},{'id': '164', 'type': 'string', 'children': [], 'value': '"-"'},{'id': '165', 'type': 'block', 'children': ['166', '179']},{'id': '166', 'type': 'if_statement', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'upstream'},{'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': 'end'},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '174', 'type': 'argument_list', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'MAX'},{'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '+'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'upstream'},{'id': '179', 'type': 'if_statement', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'downstream'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '187', 'type': 'argument_list', 'children': ['188', '189']},{'id': '188', 'type': 'integer', 'children': [], 'value': '0'},{'id': '189', 'type': 'binary_operator', 'children': ['190', '191'], 'value': '-'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'downstream'},{'id': '192', 'type': 'if_statement', 'children': ['193', '198']},{'id': '193', 'type': 'comparison_operator', 'children': ['194', '197'], 'value': '>'},{'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '-'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '197', 'type': 'integer', 'children': [], 'value': '0'},{'id': '198', 'type': 'block', 'children': ['199']},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'last_bitset'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'set_range'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '206', 'type': 'binary_operator', 'children': ['207', '208'], 'value': '-'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '209', 'type': 'return_statement', 'children': ['210']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'bitsets'} | def binned_bitsets_proximity( f, chrom_col=0, start_col=1, end_col=2, strand_col=5, upstream=0, downstream=0 ):
last_chrom = None
last_bitset = None
bitsets = dict()
for line in f:
if line.startswith("
fields = line.split()
strand = "+"
if len(fields) >= strand_col + 1:
if fields[strand_col] == "-": strand = "-"
chrom = fields[chrom_col]
if chrom != last_chrom:
if chrom not in bitsets:
bitsets[chrom] = BinnedBitSet( MAX )
last_chrom = chrom
last_bitset = bitsets[chrom]
start, end = int( fields[start_col] ), int( fields[end_col] )
if strand == "+":
if upstream: start = max( 0, start - upstream )
if downstream: end = min( MAX, end + downstream )
if strand == "-":
if upstream: end = min( MAX, end + upstream )
if downstream: start = max( 0, start - downstream )
if end-start > 0:
last_bitset.set_range( start, end-start )
return bitsets |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_file'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'Class'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'is_little_endian'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '21', '29', '41', '52', '124', '132', '227', '235', '242', '246', '281']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'BinaryFileWriter'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'file'},{'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'is_little_endian'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'is_little_endian'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'start_offset'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'tell'},{'id': '28', 'type': 'argument_list', 'children': []},{'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': 'io'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'seek'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'binary_operator', 'children': ['36', '37'], 'value': '+'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'start_offset'},{'id': '37', 'type': '()', 'children': ['38']},{'id': '38', 'type': 'binary_operator', 'children': ['39', '40'], 'value': '*'},{'id': '39', 'type': 'integer', 'children': [], 'value': '8'},{'id': '40', 'type': 'integer', 'children': [], 'value': '256'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'subtables'},{'id': '44', 'type': 'list_comprehension', 'children': ['45', '46']},{'id': '45', 'type': 'list', 'children': [], 'value': '[]'},{'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '50', 'type': 'argument_list', 'children': ['51']},{'id': '51', 'type': 'integer', 'children': [], 'value': '256'},{'id': '52', 'type': 'for_statement', 'children': ['53', '56', '61']},{'id': '53', 'type': 'pattern_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'block', 'children': ['62', '70', '80', '90', '97', '104', '111']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'pair_offset'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'tell'},{'id': '69', 'type': 'argument_list', 'children': []},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'write_uint32'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'write_uint32'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'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': 'value'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'},{'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': 'io'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '104', 'type': 'expression_statement', 'children': ['105']},{'id': '105', 'type': 'assignment', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'hash'},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'cdbhash'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '120']},{'id': '113', 'type': 'attribute', 'children': ['114', '119']},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'subtables'},{'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '%'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'hash'},{'id': '118', 'type': 'integer', 'children': [], 'value': '256'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'tuple', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'hash'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'pair_offset'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'subtable_offset'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'tell'},{'id': '131', 'type': 'argument_list', 'children': []},{'id': '132', 'type': 'for_statement', 'children': ['133', '134', '135']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'subtable'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'subtables'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'if_statement', 'children': ['137', '143']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '142'], 'value': '>'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'subtable'},{'id': '142', 'type': 'integer', 'children': [], 'value': '0'},{'id': '143', 'type': 'block', 'children': ['144', '153', '166', '207']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'ncells'},{'id': '147', 'type': 'binary_operator', 'children': ['148', '152'], 'value': '*'},{'id': '148', 'type': 'call', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'subtable'},{'id': '152', 'type': 'integer', 'children': [], 'value': '2'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'cells'},{'id': '156', 'type': 'list_comprehension', 'children': ['157', '160']},{'id': '157', 'type': 'tuple', 'children': ['158', '159']},{'id': '158', 'type': 'integer', 'children': [], 'value': '0'},{'id': '159', 'type': 'integer', 'children': [], 'value': '0'},{'id': '160', 'type': 'for_in_clause', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'ncells'},{'id': '166', 'type': 'for_statement', 'children': ['167', '170', '171']},{'id': '167', 'type': 'pattern_list', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'hash'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'pair_offset'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'subtable'},{'id': '171', 'type': 'block', 'children': ['172', '181', '199']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '175', 'type': 'binary_operator', 'children': ['176', '180'], 'value': '%'},{'id': '176', 'type': '()', 'children': ['177']},{'id': '177', 'type': 'binary_operator', 'children': ['178', '179'], 'value': '>>'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'hash'},{'id': '179', 'type': 'integer', 'children': [], 'value': '8'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'ncells'},{'id': '181', 'type': 'while_statement', 'children': ['182', '189']},{'id': '182', 'type': 'comparison_operator', 'children': ['183', '188'], 'value': '!='},{'id': '183', 'type': 'subscript', 'children': ['184', '187']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'cells'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '187', 'type': 'integer', 'children': [], 'value': '1'},{'id': '188', 'type': 'integer', 'children': [], 'value': '0'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '193', 'type': 'binary_operator', 'children': ['194', '198'], 'value': '%'},{'id': '194', 'type': '()', 'children': ['195']},{'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '+'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '197', 'type': 'integer', 'children': [], 'value': '1'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'ncells'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '204']},{'id': '201', 'type': 'subscript', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'cells'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '204', 'type': 'tuple', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'hash'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'pair_offset'},{'id': '207', 'type': 'for_statement', 'children': ['208', '211', '212']},{'id': '208', 'type': 'pattern_list', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'hash'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'pair_offset'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'cells'},{'id': '212', 'type': 'block', 'children': ['213', '220']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'write_uint32'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'hash'},{'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': 'io'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'write_uint32'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'pair_offset'},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'end_offset'},{'id': '230', 'type': 'call', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'tell'},{'id': '234', 'type': 'argument_list', 'children': []},{'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': 'io'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'seek'},{'id': '240', 'type': 'argument_list', 'children': ['241']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'start_offset'},{'id': '242', 'type': 'expression_statement', 'children': ['243']},{'id': '243', 'type': 'assignment', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'subtable_offset'},{'id': '246', 'type': 'for_statement', 'children': ['247', '248', '249']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'subtable'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'subtables'},{'id': '249', 'type': 'block', 'children': ['250', '257', '269']},{'id': '250', 'type': 'expression_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'write_uint32'},{'id': '255', 'type': 'argument_list', 'children': ['256']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'index'},{'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': 'io'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'write_uint32'},{'id': '262', 'type': 'argument_list', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '265', 'type': 'argument_list', 'children': ['266']},{'id': '266', 'type': 'binary_operator', 'children': ['267', '268'], 'value': '*'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'subtable'},{'id': '268', 'type': 'integer', 'children': [], 'value': '2'},{'id': '269', 'type': 'expression_statement', 'children': ['270']},{'id': '270', 'type': 'augmented_assignment', 'children': ['271', '272'], 'value': '+='},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '272', 'type': 'binary_operator', 'children': ['273', '280'], 'value': '*'},{'id': '273', 'type': '()', 'children': ['274']},{'id': '274', 'type': 'binary_operator', 'children': ['275', '279'], 'value': '*'},{'id': '275', 'type': 'call', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '277', 'type': 'argument_list', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'subtable'},{'id': '279', 'type': 'integer', 'children': [], 'value': '2'},{'id': '280', 'type': 'integer', 'children': [], 'value': '8'},{'id': '281', 'type': 'expression_statement', 'children': ['282']},{'id': '282', 'type': 'call', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'io'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'seek'},{'id': '286', 'type': 'argument_list', 'children': ['287']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'end_offset'} | def to_file( Class, dict, file, is_little_endian=True ):
io = BinaryFileWriter( file, is_little_endian=is_little_endian )
start_offset = io.tell()
io.seek( start_offset + ( 8 * 256 ) )
subtables = [ [] for i in range(256) ]
for key, value in dict.items():
pair_offset = io.tell()
io.write_uint32( len( key ) )
io.write_uint32( len( value ) )
io.write( key )
io.write( value )
hash = cdbhash( key )
subtables[ hash % 256 ].append( ( hash, pair_offset ) )
subtable_offset = io.tell()
for subtable in subtables:
if len( subtable ) > 0:
ncells = len( subtable ) * 2
cells = [ (0,0) for i in range( ncells ) ]
for hash, pair_offset in subtable:
index = ( hash >> 8 ) % ncells
while cells[index][1] != 0:
index = ( index + 1 ) % ncells
cells[index] = ( hash, pair_offset )
for hash, pair_offset in cells:
io.write_uint32( hash )
io.write_uint32( pair_offset )
end_offset = io.tell()
io.seek( start_offset )
index = subtable_offset
for subtable in subtables:
io.write_uint32( index )
io.write_uint32( len( subtable * 2 ) )
index += ( len( subtable ) * 2 ) * 8
io.seek( end_offset ) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'transform'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'chain_CT_CQ'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'max_gap'},{'id': '7', 'type': 'block', 'children': ['8', '15', '47', '78', '84', '90', '109', '129', '136', '208', '215', '222', '240', '258', '316', '351']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '14']},{'id': '10', 'type': 'tuple_pattern', 'children': ['11', '12', '13']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'CT'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'CQ'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'chain_CT_CQ'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '20']},{'id': '17', 'type': 'pattern_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '20', 'type': 'expression_list', 'children': ['21', '34']},{'id': '21', 'type': 'binary_operator', 'children': ['22', '31'], 'value': '-'},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '24', 'type': 'argument_list', 'children': ['25', '28']},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '27', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'tStart'},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'tStart'},{'id': '34', 'type': 'binary_operator', 'children': ['35', '44'], 'value': '-'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '37', 'type': 'argument_list', 'children': ['38', '41']},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '40', 'type': 'string', 'children': [], 'value': "'end'"},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'tEnd'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'tStart'},{'id': '47', 'type': 'assert_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'comparison_operator', 'children': ['54', '66'], 'value': '=='},{'id': '54', 'type': '()', 'children': ['55']},{'id': '55', 'type': 'binary_operator', 'children': ['56', '61'], 'value': '-'},{'id': '56', 'type': 'subscript', 'children': ['57', '58', '60']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'CT'},{'id': '58', 'type': 'slice', 'children': ['59']},{'id': '59', 'type': 'colon', 'children': []},{'id': '60', 'type': 'integer', 'children': [], 'value': '1'},{'id': '61', 'type': 'subscript', 'children': ['62', '63', '65']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'CT'},{'id': '63', 'type': 'slice', 'children': ['64']},{'id': '64', 'type': 'colon', 'children': []},{'id': '65', 'type': 'integer', 'children': [], 'value': '0'},{'id': '66', 'type': '()', 'children': ['67']},{'id': '67', 'type': 'binary_operator', 'children': ['68', '73'], 'value': '-'},{'id': '68', 'type': 'subscript', 'children': ['69', '70', '72']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'CQ'},{'id': '70', 'type': 'slice', 'children': ['71']},{'id': '71', 'type': 'colon', 'children': []},{'id': '72', 'type': 'integer', 'children': [], 'value': '1'},{'id': '73', 'type': 'subscript', 'children': ['74', '75', '77']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'CQ'},{'id': '75', 'type': 'slice', 'children': ['76']},{'id': '76', 'type': 'colon', 'children': []},{'id': '77', 'type': 'integer', 'children': [], 'value': '0'},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'to_chrom'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'qName'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'to_gab_start'},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'qStart'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '93', 'type': 'subscript', 'children': ['94', '108']},{'id': '94', 'type': 'subscript', 'children': ['95', '107']},{'id': '95', 'type': 'call', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '99', 'type': 'argument_list', 'children': ['100']},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '106'], 'value': '>'},{'id': '101', 'type': 'subscript', 'children': ['102', '103', '105']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'CT'},{'id': '103', 'type': 'slice', 'children': ['104']},{'id': '104', 'type': 'colon', 'children': []},{'id': '105', 'type': 'integer', 'children': [], 'value': '1'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '107', 'type': 'integer', 'children': [], 'value': '0'},{'id': '108', 'type': 'integer', 'children': [], 'value': '0'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'end_idx'},{'id': '112', 'type': 'subscript', 'children': ['113', '127']},{'id': '113', 'type': 'subscript', 'children': ['114', '126']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '125'], 'value': '<'},{'id': '120', 'type': 'subscript', 'children': ['121', '122', '124']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'CT'},{'id': '122', 'type': 'slice', 'children': ['123']},{'id': '123', 'type': 'colon', 'children': []},{'id': '124', 'type': 'integer', 'children': [], 'value': '0'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '126', 'type': 'integer', 'children': [], 'value': '0'},{'id': '127', 'type': 'unary_operator', 'children': ['128'], 'value': '-'},{'id': '128', 'type': 'integer', 'children': [], 'value': '1'},{'id': '129', 'type': 'if_statement', 'children': ['130', '133']},{'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': '>'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'end_idx'},{'id': '133', 'type': 'block', 'children': ['134']},{'id': '134', 'type': 'return_statement', 'children': ['135']},{'id': '135', 'type': 'list', 'children': [], 'value': '[]'},{'id': '136', 'type': 'if_statement', 'children': ['137', '146']},{'id': '137', 'type': 'boolean_operator', 'children': ['138', '141'], 'value': 'and'},{'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': '>='},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'max_gap'},{'id': '140', 'type': 'integer', 'children': [], 'value': '0'},{'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': '<'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '-'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'end_idx'},{'id': '145', 'type': 'integer', 'children': [], 'value': '1'},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'if_statement', 'children': ['148', '205']},{'id': '148', 'type': 'boolean_operator', 'children': ['149', '177'], 'value': 'or'},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '176'], 'value': '>'},{'id': '150', 'type': 'call', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'binary_operator', 'children': ['156', '166'], 'value': '-'},{'id': '156', 'type': 'subscript', 'children': ['157', '158', '165']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'CT'},{'id': '158', 'type': 'slice', 'children': ['159', '163', '164']},{'id': '159', 'type': '()', 'children': ['160']},{'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '+'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'colon', 'children': []},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'end_idx'},{'id': '165', 'type': 'integer', 'children': [], 'value': '0'},{'id': '166', 'type': 'subscript', 'children': ['167', '168', '175']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'CT'},{'id': '168', 'type': 'slice', 'children': ['169', '170', '171']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '170', 'type': 'colon', 'children': []},{'id': '171', 'type': '()', 'children': ['172']},{'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '-'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'end_idx'},{'id': '174', 'type': 'integer', 'children': [], 'value': '1'},{'id': '175', 'type': 'integer', 'children': [], 'value': '1'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'max_gap'},{'id': '177', 'type': 'comparison_operator', 'children': ['178', '204'], 'value': '>'},{'id': '178', 'type': 'call', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'binary_operator', 'children': ['184', '194'], 'value': '-'},{'id': '184', 'type': 'subscript', 'children': ['185', '186', '193']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'CQ'},{'id': '186', 'type': 'slice', 'children': ['187', '191', '192']},{'id': '187', 'type': '()', 'children': ['188']},{'id': '188', 'type': 'binary_operator', 'children': ['189', '190'], 'value': '+'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '190', 'type': 'integer', 'children': [], 'value': '1'},{'id': '191', 'type': 'colon', 'children': []},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'end_idx'},{'id': '193', 'type': 'integer', 'children': [], 'value': '0'},{'id': '194', 'type': 'subscript', 'children': ['195', '196', '203']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'CQ'},{'id': '196', 'type': 'slice', 'children': ['197', '198', '199']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '198', 'type': 'colon', 'children': []},{'id': '199', 'type': '()', 'children': ['200']},{'id': '200', 'type': 'binary_operator', 'children': ['201', '202'], 'value': '-'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'end_idx'},{'id': '202', 'type': 'integer', 'children': [], 'value': '1'},{'id': '203', 'type': 'integer', 'children': [], 'value': '1'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'max_gap'},{'id': '205', 'type': 'block', 'children': ['206']},{'id': '206', 'type': 'return_statement', 'children': ['207']},{'id': '207', 'type': 'list', 'children': [], 'value': '[]'},{'id': '208', 'type': 'assert_statement', 'children': ['209']},{'id': '209', 'type': 'comparison_operator', 'children': ['210', '211'], 'value': '<'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '211', 'type': 'subscript', 'children': ['212', '213', '214']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'CT'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '214', 'type': 'integer', 'children': [], 'value': '1'},{'id': '215', 'type': 'assert_statement', 'children': ['216']},{'id': '216', 'type': 'comparison_operator', 'children': ['217', '221'], 'value': '<'},{'id': '217', 'type': 'subscript', 'children': ['218', '219', '220']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'CT'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'end_idx'},{'id': '220', 'type': 'integer', 'children': [], 'value': '0'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'to_start'},{'id': '225', 'type': 'binary_operator', 'children': ['226', '230'], 'value': '+'},{'id': '226', 'type': 'subscript', 'children': ['227', '228', '229']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'CQ'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '229', 'type': 'integer', 'children': [], 'value': '0'},{'id': '230', 'type': 'call', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '232', 'type': 'argument_list', 'children': ['233', '234']},{'id': '233', 'type': 'integer', 'children': [], 'value': '0'},{'id': '234', 'type': 'binary_operator', 'children': ['235', '236'], 'value': '-'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '236', 'type': 'subscript', 'children': ['237', '238', '239']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'CT'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '239', 'type': 'integer', 'children': [], 'value': '0'},{'id': '240', 'type': 'expression_statement', 'children': ['241']},{'id': '241', 'type': 'assignment', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'to_end'},{'id': '243', 'type': 'binary_operator', 'children': ['244', '248'], 'value': '-'},{'id': '244', 'type': 'subscript', 'children': ['245', '246', '247']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'CQ'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'end_idx'},{'id': '247', 'type': 'integer', 'children': [], 'value': '1'},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '250', 'type': 'argument_list', 'children': ['251', '252']},{'id': '251', 'type': 'integer', 'children': [], 'value': '0'},{'id': '252', 'type': 'binary_operator', 'children': ['253', '257'], 'value': '-'},{'id': '253', 'type': 'subscript', 'children': ['254', '255', '256']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'CT'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'end_idx'},{'id': '256', 'type': 'integer', 'children': [], 'value': '1'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'end'},{'id': '258', 'type': 'if_statement', 'children': ['259', '262', '270']},{'id': '259', 'type': 'comparison_operator', 'children': ['260', '261'], 'value': '=='},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'end_idx'},{'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': 'slices'},{'id': '266', 'type': 'list', 'children': ['267'], 'value': '[(to_start, to_end)]'},{'id': '267', 'type': 'tuple', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'to_start'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'to_end'},{'id': '270', 'type': 'else_clause', 'children': ['271']},{'id': '271', 'type': 'block', 'children': ['272', '282', '304']},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'slices'},{'id': '275', 'type': 'list', 'children': ['276'], 'value': '[(to_start, CQ[start_idx,1])]'},{'id': '276', 'type': 'tuple', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'to_start'},{'id': '278', 'type': 'subscript', 'children': ['279', '280', '281']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'CQ'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '281', 'type': 'integer', 'children': [], 'value': '1'},{'id': '282', 'type': 'expression_statement', 'children': ['283']},{'id': '283', 'type': 'augmented_assignment', 'children': ['284', '285'], 'value': '+='},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'slices'},{'id': '285', 'type': 'list_comprehension', 'children': ['286', '295']},{'id': '286', 'type': 'tuple', 'children': ['287', '291']},{'id': '287', 'type': 'subscript', 'children': ['288', '289', '290']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'CQ'},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '290', 'type': 'integer', 'children': [], 'value': '0'},{'id': '291', 'type': 'subscript', 'children': ['292', '293', '294']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'CQ'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '294', 'type': 'integer', 'children': [], 'value': '1'},{'id': '295', 'type': 'for_in_clause', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '297', 'type': 'call', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '299', 'type': 'argument_list', 'children': ['300', '303']},{'id': '300', 'type': 'binary_operator', 'children': ['301', '302'], 'value': '+'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'start_idx'},{'id': '302', 'type': 'integer', 'children': [], 'value': '1'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'end_idx'},{'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': 'slices'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'tuple', 'children': ['311', '315']},{'id': '311', 'type': 'subscript', 'children': ['312', '313', '314']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'CQ'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'end_idx'},{'id': '314', 'type': 'integer', 'children': [], 'value': '0'},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'to_end'},{'id': '316', 'type': 'if_statement', 'children': ['317', '322']},{'id': '317', 'type': 'comparison_operator', 'children': ['318', '321'], 'value': '=='},{'id': '318', 'type': 'attribute', 'children': ['319', '320']},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'qStrand'},{'id': '321', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '322', 'type': 'block', 'children': ['323', '333']},{'id': '323', 'type': 'expression_statement', 'children': ['324']},{'id': '324', 'type': 'assignment', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'Sz'},{'id': '326', 'type': 'binary_operator', 'children': ['327', '330'], 'value': '-'},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'qEnd'},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'qStart'},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'assignment', 'children': ['335', '336']},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'slices'},{'id': '336', 'type': 'list_comprehension', 'children': ['337', '348']},{'id': '337', 'type': 'tuple', 'children': ['338', '343']},{'id': '338', 'type': 'binary_operator', 'children': ['339', '340'], 'value': '-'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'Sz'},{'id': '340', 'type': 'subscript', 'children': ['341', '342']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '342', 'type': 'integer', 'children': [], 'value': '1'},{'id': '343', 'type': 'binary_operator', 'children': ['344', '345'], 'value': '-'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'Sz'},{'id': '345', 'type': 'subscript', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '347', 'type': 'integer', 'children': [], 'value': '0'},{'id': '348', 'type': 'for_in_clause', 'children': ['349', '350']},{'id': '349', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'slices'},{'id': '351', 'type': 'return_statement', 'children': ['352']},{'id': '352', 'type': 'list_comprehension', 'children': ['353', '368']},{'id': '353', 'type': 'tuple', 'children': ['354', '355', '360', '365']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'to_chrom'},{'id': '355', 'type': 'binary_operator', 'children': ['356', '357'], 'value': '+'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'to_gab_start'},{'id': '357', 'type': 'subscript', 'children': ['358', '359']},{'id': '358', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '359', 'type': 'integer', 'children': [], 'value': '0'},{'id': '360', 'type': 'binary_operator', 'children': ['361', '362'], 'value': '+'},{'id': '361', 'type': 'identifier', 'children': [], 'value': 'to_gab_start'},{'id': '362', 'type': 'subscript', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '364', 'type': 'integer', 'children': [], 'value': '1'},{'id': '365', 'type': 'subscript', 'children': ['366', '367']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'elem'},{'id': '367', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '368', 'type': 'for_in_clause', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'slices'} | def transform(elem, chain_CT_CQ, max_gap):
(chain, CT, CQ) = chain_CT_CQ
start, end = max(elem['start'], chain.tStart) - chain.tStart, min(elem['end'], chain.tEnd) - chain.tStart
assert np.all( (CT[:,1] - CT[:,0]) == (CQ[:,1] - CQ[:,0]) )
to_chrom = chain.qName
to_gab_start = chain.qStart
start_idx = np.where( CT[:,1] > start )[0][0]
end_idx = np.where( CT[:,0] < end )[0][-1]
if start_idx > end_idx:
return []
if max_gap >= 0 and start_idx < end_idx - 1:
if np.max(CT[(start_idx+1):end_idx,0] - CT[start_idx:(end_idx-1),1]) > max_gap or np.max(CQ[(start_idx+1):end_idx,0] - CQ[start_idx:(end_idx-1),1]) > max_gap:
return []
assert start < CT[start_idx, 1]
assert CT[end_idx, 0] < end
to_start = CQ[start_idx, 0] + max(0, start - CT[start_idx,0])
to_end = CQ[end_idx, 1] - max(0, CT[end_idx, 1] - end)
if start_idx == end_idx:
slices = [(to_start, to_end)]
else:
slices = [(to_start, CQ[start_idx,1])]
slices += [(CQ[i,0], CQ[i,1]) for i in range(start_idx+1, end_idx)]
slices.append( (CQ[end_idx,0], to_end) )
if chain.qStrand == '-':
Sz = chain.qEnd - chain.qStart
slices = [(Sz-t[1], Sz-t[0]) for t in slices]
return [(to_chrom, to_gab_start + t[0], to_gab_start + t[1], elem['id']) for t in slices] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'visit_Method'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '6', 'type': 'block', 'children': ['7', '15', '59', '86', '109', '133']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'resolved_method'},{'id': '10', 'type': 'attribute', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '15', 'type': 'function_definition', 'children': ['16', '17', '20']},{'id': '16', 'type': 'function_name', 'children': [], 'value': 'get_params'},{'id': '17', 'type': 'parameters', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'extra_bindings'},{'id': '20', 'type': 'block', 'children': ['21', '25', '57']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '24', 'type': 'list', 'children': [], 'value': '[]'},{'id': '25', 'type': 'for_statement', 'children': ['26', '27', '30']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '30', 'type': 'block', 'children': ['31', '48']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'resolved_param'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'texpr'},{'id': '36', 'type': 'argument_list', 'children': ['37', '42', '47']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'bindings'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'extra_bindings'},{'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': 'result'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'resolved_param'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '57', 'type': 'return_statement', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '59', 'type': 'function_definition', 'children': ['60', '61', '64']},{'id': '60', 'type': 'function_name', 'children': [], 'value': 'get_return_type'},{'id': '61', 'type': 'parameters', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'extra_bindings'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'attribute', 'children': ['67', '85']},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'texpr'},{'id': '69', 'type': 'argument_list', 'children': ['70', '77', '84']},{'id': '70', 'type': 'attribute', 'children': ['71', '76']},{'id': '71', 'type': 'attribute', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '77', 'type': 'attribute', 'children': ['78', '83']},{'id': '78', 'type': 'attribute', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'bindings'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'extra_bindings'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '86', 'type': 'function_definition', 'children': ['87', '88', '92']},{'id': '87', 'type': 'function_name', 'children': [], 'value': 'signature'},{'id': '88', 'type': 'parameters', 'children': ['89', '90', '91']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'return_type'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '%'},{'id': '95', 'type': 'string', 'children': [], 'value': '"%s %s(%s)"'},{'id': '96', 'type': 'tuple', 'children': ['97', '98', '103']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'return_type'},{'id': '98', 'type': 'attribute', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'string', 'children': [], 'value': '", "'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'interfaces'},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '114', 'type': 'generator_expression', 'children': ['115', '116', '123']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '116', 'type': 'for_in_clause', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '118', 'type': 'attribute', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'clazz'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'bases'},{'id': '123', 'type': 'if_clause', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '126', 'type': 'argument_list', 'children': ['127', '132']},{'id': '127', 'type': 'attribute', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'Interface'},{'id': '133', 'type': 'for_statement', 'children': ['134', '135', '136']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'interface'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'interfaces'},{'id': '136', 'type': 'block', 'children': ['137', '143']},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'interfaceTypeExpr'},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'interface'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '143', 'type': 'for_statement', 'children': ['144', '145', '150']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'definition'},{'id': '145', 'type': 'attribute', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'interfaceTypeExpr'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'definitions'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'if_statement', 'children': ['152', '163']},{'id': '152', 'type': 'comparison_operator', 'children': ['153', '158'], 'value': '=='},{'id': '153', 'type': 'attribute', 'children': ['154', '157']},{'id': '154', 'type': 'attribute', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'definition'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '158', 'type': 'attribute', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '163', 'type': 'block', 'children': ['164', '172', '186', '196', '210', '220']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'resolved_definition'},{'id': '167', 'type': 'attribute', 'children': ['168', '171']},{'id': '168', 'type': 'attribute', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'definition'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'method_params'},{'id': '175', 'type': 'call', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'get_params'},{'id': '177', 'type': 'argument_list', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'resolved_method'},{'id': '179', 'type': 'attribute', 'children': ['180', '185']},{'id': '180', 'type': 'attribute', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'clazz'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'bindings'},{'id': '186', 'type': 'expression_statement', 'children': ['187']},{'id': '187', 'type': 'assignment', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'definition_params'},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'get_params'},{'id': '191', 'type': 'argument_list', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'resolved_definition'},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'interfaceTypeExpr'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'bindings'},{'id': '196', 'type': 'expression_statement', 'children': ['197']},{'id': '197', 'type': 'assignment', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'method_return'},{'id': '199', 'type': 'call', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'get_return_type'},{'id': '201', 'type': 'argument_list', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'resolved_method'},{'id': '203', 'type': 'attribute', 'children': ['204', '209']},{'id': '204', 'type': 'attribute', 'children': ['205', '208']},{'id': '205', 'type': 'attribute', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'clazz'},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'bindings'},{'id': '210', 'type': 'expression_statement', 'children': ['211']},{'id': '211', 'type': 'assignment', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'definition_return'},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'get_return_type'},{'id': '215', 'type': 'argument_list', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'resolved_definition'},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'interfaceTypeExpr'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'bindings'},{'id': '220', 'type': 'if_statement', 'children': ['221', '228']},{'id': '221', 'type': 'boolean_operator', 'children': ['222', '225'], 'value': 'or'},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': '!='},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'method_params'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'definition_params'},{'id': '225', 'type': 'comparison_operator', 'children': ['226', '227'], 'value': '!='},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'method_return'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'definition_return'},{'id': '228', 'type': 'block', 'children': ['229']},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'call', 'children': ['231', '236']},{'id': '231', 'type': 'attribute', 'children': ['232', '235']},{'id': '232', 'type': 'attribute', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'errors'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '236', 'type': 'argument_list', 'children': ['237']},{'id': '237', 'type': 'binary_operator', 'children': ['238', '239'], 'value': '%'},{'id': '238', 'type': 'string', 'children': [], 'value': '"%s: method signature \'%s\' on %s does not match method \'%s\' on interface %s"'},{'id': '239', 'type': 'tuple', 'children': ['240', '244', '250', '259', '265']},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'lineinfo'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '244', 'type': 'call', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '246', 'type': 'argument_list', 'children': ['247', '248', '249']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'resolved_method'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'method_return'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'method_params'},{'id': '250', 'type': 'attribute', 'children': ['251', '258']},{'id': '251', 'type': 'attribute', 'children': ['252', '257']},{'id': '252', 'type': 'attribute', 'children': ['253', '256']},{'id': '253', 'type': 'attribute', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'clazz'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'signature'},{'id': '261', 'type': 'argument_list', 'children': ['262', '263', '264']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'resolved_definition'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'definition_return'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'definition_params'},{'id': '265', 'type': 'attribute', 'children': ['266', '271']},{'id': '266', 'type': 'attribute', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'interface'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'resolved'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'id'} | def visit_Method(self, method):
resolved_method = method.resolved.type
def get_params(method, extra_bindings):
result = []
for param in method.params:
resolved_param = texpr(param.resolved.type, param.resolved.bindings, extra_bindings)
result.append(resolved_param.id)
return result
def get_return_type(method, extra_bindings):
return texpr(method.type.resolved.type, method.type.resolved.bindings,
extra_bindings).id
def signature(method, return_type, params):
return "%s %s(%s)" % (return_type, method.name.text, ", ".join(params))
interfaces = list(t for t in method.clazz.bases if isinstance(t.resolved.type, Interface))
for interface in interfaces:
interfaceTypeExpr = interface.resolved
for definition in interfaceTypeExpr.type.definitions:
if definition.name.text == method.name.text:
resolved_definition = definition.resolved.type
method_params = get_params(resolved_method, method.clazz.resolved.bindings)
definition_params = get_params(resolved_definition, interfaceTypeExpr.bindings)
method_return = get_return_type(resolved_method, method.clazz.resolved.bindings)
definition_return = get_return_type(resolved_definition, interfaceTypeExpr.bindings)
if method_params != definition_params or method_return != definition_return:
self.errors.append(
"%s: method signature '%s' on %s does not match method '%s' on interface %s" % (
lineinfo(method), signature(resolved_method, method_return, method_params),
method.clazz.resolved.type.id,
signature(resolved_definition, definition_return, definition_params),
interface.resolved.type.id)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'file_search'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '30', '74']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '18', 'type': 'argument_list', 'children': ['19', '24', '27']},{'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'apikey'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'api_key'},{'id': '24', 'type': 'keyword_argument', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'offset'},{'id': '30', 'type': 'try_statement', 'children': ['31', '56']},{'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': 'response'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '39', 'type': 'argument_list', 'children': ['40', '45', '48', '53']},{'id': '40', 'type': 'binary_operator', 'children': ['41', '44'], 'value': '+'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '44', 'type': 'string', 'children': [], 'value': "'file/search'"},{'id': '45', 'type': 'keyword_argument', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'proxies'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'proxies'},{'id': '53', 'type': 'keyword_argument', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '56', 'type': 'except_clause', 'children': ['57', '63']},{'id': '57', 'type': 'as_pattern', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'RequestException'},{'id': '61', 'type': 'as_pattern_target', 'children': ['62']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': '_return_response_and_status_code'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'response'} | def file_search(self, query, offset=None, timeout=None):
params = dict(apikey=self.api_key, query=query, offset=offset)
try:
response = requests.get(self.base + 'file/search', params=params, proxies=self.proxies, timeout=timeout)
except requests.RequestException as e:
return dict(error=str(e))
return _return_response_and_status_code(response) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_handle_retry'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '6', 'type': 'block', 'children': ['7', '18', '28', '48', '67', '117', '152']},{'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': 'exc_t'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'exc_v'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'exc_tb'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'exc_info'},{'id': '17', 'type': 'argument_list', 'children': []},{'id': '18', 'type': 'if_statement', 'children': ['19', '22']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'is'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'exc_t'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'raise_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': "'Must be called in except block.'"},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'retry_on_exc'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'generator_expression', 'children': ['35', '36', '41']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_retry_on'},{'id': '41', 'type': 'if_clause', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'inspect'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'retry_on_codes'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'generator_expression', 'children': ['55', '56', '61']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '56', 'type': 'for_in_clause', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_retry_on'},{'id': '61', 'type': 'if_clause', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '64', 'type': 'argument_list', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '67', 'type': 'if_statement', 'children': ['68', '73', '98']},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '70', 'type': 'argument_list', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'exc_t'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'ZendeskError'},{'id': '73', 'type': 'block', 'children': ['74', '80']},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'exc_v'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'error_code'},{'id': '80', 'type': 'if_statement', 'children': ['81', '88']},{'id': '81', 'type': 'boolean_operator', 'children': ['82', '85'], 'value': 'and'},{'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': 'not'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'exc_t'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'retry_on_exc'},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'not'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'code'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'retry_on_codes'},{'id': '88', 'type': 'block', 'children': ['89']},{'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': 'six'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'reraise'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96', '97']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'exc_t'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'exc_v'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'exc_tb'},{'id': '98', 'type': 'else_clause', 'children': ['99']},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'if_statement', 'children': ['101', '107']},{'id': '101', 'type': 'not_operator', 'children': ['102']},{'id': '102', 'type': 'call', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '104', 'type': 'argument_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'exc_t'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'retry_on_exc'},{'id': '107', 'type': 'block', 'children': ['108']},{'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': 'six'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'reraise'},{'id': '113', 'type': 'argument_list', 'children': ['114', '115', '116']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'exc_t'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'exc_v'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'exc_tb'},{'id': '117', 'type': 'if_statement', 'children': ['118', '121']},{'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'is'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '120', 'type': 'None', 'children': []},{'id': '121', 'type': 'block', 'children': ['122']},{'id': '122', 'type': 'try_statement', 'children': ['123', '146']},{'id': '123', 'type': 'block', 'children': ['124', '139']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'retry_after'},{'id': '127', 'type': 'call', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'call', 'children': ['131', '136']},{'id': '131', 'type': 'attribute', 'children': ['132', '135']},{'id': '132', 'type': 'attribute', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'string', 'children': [], 'value': "'Retry-After'"},{'id': '138', 'type': 'integer', 'children': [], 'value': '0'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '144', 'type': 'argument_list', 'children': ['145']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'retry_after'},{'id': '146', 'type': 'except_clause', 'children': ['147', '150']},{'id': '147', 'type': 'tuple', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '150', 'type': 'block', 'children': ['151']},{'id': '151', 'type': 'pass_statement', 'children': []},{'id': '152', 'type': 'return_statement', 'children': ['153']},{'id': '153', 'type': 'True', 'children': []} | def _handle_retry(self, resp):
exc_t, exc_v, exc_tb = sys.exc_info()
if exc_t is None:
raise TypeError('Must be called in except block.')
retry_on_exc = tuple(
(x for x in self._retry_on if inspect.isclass(x)))
retry_on_codes = tuple(
(x for x in self._retry_on if isinstance(x, int)))
if issubclass(exc_t, ZendeskError):
code = exc_v.error_code
if exc_t not in retry_on_exc and code not in retry_on_codes:
six.reraise(exc_t, exc_v, exc_tb)
else:
if not issubclass(exc_t, retry_on_exc):
six.reraise(exc_t, exc_v, exc_tb)
if resp is not None:
try:
retry_after = float(resp.headers.get('Retry-After', 0))
time.sleep(retry_after)
except (TypeError, ValueError):
pass
return True |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_event_triggers'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '18', '26', '105', '114', '349', '366', '379', '387', '395']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'nvrflag'},{'id': '13', 'type': 'False', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'event_xml'},{'id': '17', 'type': 'list', 'children': [], 'value': '[]'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '21', 'type': 'binary_operator', 'children': ['22', '23'], 'value': '%'},{'id': '22', 'type': 'string', 'children': [], 'value': "'%s/ISAPI/Event/triggers'"},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'root_url'},{'id': '26', 'type': 'try_statement', 'children': ['27', '79']},{'id': '27', 'type': 'block', 'children': ['28', '42']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'response'},{'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': 'hik_request'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'CONNECT_TIMEOUT'},{'id': '42', 'type': 'if_statement', 'children': ['43', '52']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '47'], 'value': '=='},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '47', 'type': 'attribute', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'not_found'},{'id': '52', 'type': 'block', 'children': ['53', '60', '68']},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'string', 'children': [], 'value': "'Using alternate triggers URL.'"},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '%'},{'id': '64', 'type': 'string', 'children': [], 'value': "'%s/Event/triggers'"},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'root_url'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '71', 'type': 'call', 'children': ['72', '77']},{'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': 'hik_request'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '79', 'type': 'except_clause', 'children': ['80', '94']},{'id': '80', 'type': 'as_pattern', 'children': ['81', '92']},{'id': '81', 'type': 'tuple', 'children': ['82', '87']},{'id': '82', 'type': 'attribute', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'RequestException'},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'},{'id': '92', 'type': 'as_pattern_target', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '94', 'type': 'block', 'children': ['95', '103']},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'string', 'children': [], 'value': "'Unable to fetch events, error: %s'"},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'None', 'children': []},{'id': '105', 'type': 'if_statement', 'children': ['106', '111']},{'id': '106', 'type': 'comparison_operator', 'children': ['107', '110'], 'value': '!='},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '110', 'type': 'integer', 'children': [], 'value': '200'},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'return_statement', 'children': ['113']},{'id': '113', 'type': 'None', 'children': []},{'id': '114', 'type': 'try_statement', 'children': ['115', '329']},{'id': '115', 'type': 'block', 'children': ['116', '127', '185']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'assignment', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '119', 'type': 'call', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'ET'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'fromstring'},{'id': '123', 'type': 'argument_list', 'children': ['124']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '127', 'type': 'if_statement', 'children': ['128', '141', '158']},{'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': 'content'},{'id': '132', 'type': 'integer', 'children': [], 'value': '0'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'element_query'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'string', 'children': [], 'value': "'EventTrigger'"},{'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': 'event_xml'},{'id': '145', 'type': 'call', 'children': ['146', '151']},{'id': '146', 'type': 'attribute', 'children': ['147', '150']},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '149', 'type': 'integer', 'children': [], 'value': '0'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'findall'},{'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': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'element_query'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'string', 'children': [], 'value': "'EventTrigger'"},{'id': '158', 'type': 'elif_clause', 'children': ['159', '170']},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '163', 'type': 'argument_list', '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': 'element_query'},{'id': '168', 'type': 'argument_list', 'children': ['169']},{'id': '169', 'type': 'string', 'children': [], 'value': "'EventTrigger'"},{'id': '170', 'type': 'block', 'children': ['171']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'assignment', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'event_xml'},{'id': '174', 'type': 'call', 'children': ['175', '178']},{'id': '175', 'type': 'attribute', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'content'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'findall'},{'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': 'self'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'element_query'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'string', 'children': [], 'value': "'EventTrigger'"},{'id': '185', 'type': 'for_statement', 'children': ['186', '187', '188']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'eventtrigger'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'event_xml'},{'id': '188', 'type': 'block', 'children': ['189', '203', '209', '223', '227', '231', '279']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'ettype'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'eventtrigger'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '196', 'type': 'argument_list', 'children': ['197']},{'id': '197', 'type': 'call', 'children': ['198', '201']},{'id': '198', 'type': 'attribute', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'element_query'},{'id': '201', 'type': 'argument_list', 'children': ['202']},{'id': '202', 'type': 'string', 'children': [], 'value': "'eventType'"},{'id': '203', 'type': 'if_statement', 'children': ['204', '207']},{'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': 'is'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'ettype'},{'id': '206', 'type': 'None', 'children': []},{'id': '207', 'type': 'block', 'children': ['208']},{'id': '208', 'type': 'break_statement', 'children': []},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'assignment', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'etnotify'},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'eventtrigger'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'element_query'},{'id': '221', 'type': 'argument_list', 'children': ['222']},{'id': '222', 'type': 'string', 'children': [], 'value': "'EventTriggerNotificationList'"},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'etchannel'},{'id': '226', 'type': 'None', 'children': []},{'id': '227', 'type': 'expression_statement', 'children': ['228']},{'id': '228', 'type': 'assignment', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'etchannel_num'},{'id': '230', 'type': 'integer', 'children': [], 'value': '0'},{'id': '231', 'type': 'for_statement', 'children': ['232', '233', '234']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'node_name'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'CHANNEL_NAMES'},{'id': '234', 'type': 'block', 'children': ['235', '249']},{'id': '235', 'type': 'expression_statement', 'children': ['236']},{'id': '236', 'type': 'assignment', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'etchannel'},{'id': '238', 'type': 'call', 'children': ['239', '242']},{'id': '239', 'type': 'attribute', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'eventtrigger'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '242', 'type': 'argument_list', 'children': ['243']},{'id': '243', 'type': 'call', 'children': ['244', '247']},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'element_query'},{'id': '247', 'type': 'argument_list', 'children': ['248']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'node_name'},{'id': '249', 'type': 'if_statement', 'children': ['250', '253']},{'id': '250', 'type': 'comparison_operator', 'children': ['251', '252'], 'value': 'is'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'etchannel'},{'id': '252', 'type': 'None', 'children': []},{'id': '253', 'type': 'block', 'children': ['254']},{'id': '254', 'type': 'try_statement', 'children': ['255', '275']},{'id': '255', 'type': 'block', 'children': ['256', '265', '274']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'etchannel_num'},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'etchannel'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '265', 'type': 'if_statement', 'children': ['266', '269']},{'id': '266', 'type': 'comparison_operator', 'children': ['267', '268'], 'value': '>'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'etchannel_num'},{'id': '268', 'type': 'integer', 'children': [], 'value': '1'},{'id': '269', 'type': 'block', 'children': ['270']},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'assignment', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'nvrflag'},{'id': '273', 'type': 'True', 'children': []},{'id': '274', 'type': 'break_statement', 'children': []},{'id': '275', 'type': 'except_clause', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '277', 'type': 'block', 'children': ['278']},{'id': '278', 'type': 'pass_statement', 'children': []},{'id': '279', 'type': 'if_statement', 'children': ['280', '281']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'etnotify'},{'id': '281', 'type': 'block', 'children': ['282']},{'id': '282', 'type': 'for_statement', 'children': ['283', '284', '285']},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'notifytrigger'},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'etnotify'},{'id': '285', 'type': 'block', 'children': ['286', '300']},{'id': '286', 'type': 'expression_statement', 'children': ['287']},{'id': '287', 'type': 'assignment', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'ntype'},{'id': '289', 'type': 'call', 'children': ['290', '293']},{'id': '290', 'type': 'attribute', 'children': ['291', '292']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'notifytrigger'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'call', 'children': ['295', '298']},{'id': '295', 'type': 'attribute', 'children': ['296', '297']},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'element_query'},{'id': '298', 'type': 'argument_list', 'children': ['299']},{'id': '299', 'type': 'string', 'children': [], 'value': "'notificationMethod'"},{'id': '300', 'type': 'if_statement', 'children': ['301', '312']},{'id': '301', 'type': 'boolean_operator', 'children': ['302', '307'], 'value': 'or'},{'id': '302', 'type': 'comparison_operator', 'children': ['303', '306'], 'value': '=='},{'id': '303', 'type': 'attribute', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'ntype'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '306', 'type': 'string', 'children': [], 'value': "'center'"},{'id': '307', 'type': 'comparison_operator', 'children': ['308', '311'], 'value': '=='},{'id': '308', 'type': 'attribute', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'ntype'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '311', 'type': 'string', 'children': [], 'value': "'HTTP'"},{'id': '312', 'type': 'block', 'children': ['313']},{'id': '313', 'type': 'expression_statement', 'children': ['314']},{'id': '314', 'type': 'call', 'children': ['315', '327']},{'id': '315', 'type': 'attribute', 'children': ['316', '325', '326']},{'id': '316', 'type': 'call', 'children': ['317', '320']},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '320', 'type': 'argument_list', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'ettype'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '324', 'type': 'list', 'children': [], 'value': '[]'},{'id': '325', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '327', 'type': 'argument_list', 'children': ['328']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'etchannel_num'},{'id': '329', 'type': 'except_clause', 'children': ['330', '338']},{'id': '330', 'type': 'as_pattern', 'children': ['331', '336']},{'id': '331', 'type': 'tuple', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '333', 'type': 'attribute', 'children': ['334', '335']},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'ET'},{'id': '335', 'type': 'identifier', 'children': [], 'value': 'ParseError'},{'id': '336', 'type': 'as_pattern_target', 'children': ['337']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '338', 'type': 'block', 'children': ['339', '347']},{'id': '339', 'type': 'expression_statement', 'children': ['340']},{'id': '340', 'type': 'call', 'children': ['341', '344']},{'id': '341', 'type': 'attribute', 'children': ['342', '343']},{'id': '342', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '343', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '344', 'type': 'argument_list', 'children': ['345', '346']},{'id': '345', 'type': 'string', 'children': [], 'value': "'There was a problem finding an element: %s'"},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '347', 'type': 'return_statement', 'children': ['348']},{'id': '348', 'type': 'None', 'children': []},{'id': '349', 'type': 'if_statement', 'children': ['350', '351', '358']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'nvrflag'},{'id': '351', 'type': 'block', 'children': ['352']},{'id': '352', 'type': 'expression_statement', 'children': ['353']},{'id': '353', 'type': 'assignment', 'children': ['354', '357']},{'id': '354', 'type': 'attribute', 'children': ['355', '356']},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'device_type'},{'id': '357', 'type': 'identifier', 'children': [], 'value': 'NVR_DEVICE'},{'id': '358', 'type': 'else_clause', 'children': ['359']},{'id': '359', 'type': 'block', 'children': ['360']},{'id': '360', 'type': 'expression_statement', 'children': ['361']},{'id': '361', 'type': 'assignment', 'children': ['362', '365']},{'id': '362', 'type': 'attribute', 'children': ['363', '364']},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'device_type'},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'CAM_DEVICE'},{'id': '366', 'type': 'expression_statement', 'children': ['367']},{'id': '367', 'type': 'call', 'children': ['368', '371']},{'id': '368', 'type': 'attribute', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '371', 'type': 'argument_list', 'children': ['372', '373', '376']},{'id': '372', 'type': 'string', 'children': [], 'value': "'Processed %s as %s Device.'"},{'id': '373', 'type': 'attribute', 'children': ['374', '375']},{'id': '374', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '375', 'type': 'identifier', 'children': [], 'value': 'cam_id'},{'id': '376', 'type': 'attribute', 'children': ['377', '378']},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'device_type'},{'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': '_LOGGING'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '384', 'type': 'argument_list', 'children': ['385', '386']},{'id': '385', 'type': 'string', 'children': [], 'value': "'Found events: %s'"},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'events'},{'id': '387', 'type': 'expression_statement', 'children': ['388']},{'id': '388', 'type': 'call', 'children': ['389', '394']},{'id': '389', 'type': 'attribute', 'children': ['390', '393']},{'id': '390', 'type': 'attribute', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'hik_request'},{'id': '393', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '394', 'type': 'argument_list', 'children': []},{'id': '395', 'type': 'return_statement', 'children': ['396']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'events'} | def get_event_triggers(self):
events = {}
nvrflag = False
event_xml = []
url = '%s/ISAPI/Event/triggers' % self.root_url
try:
response = self.hik_request.get(url, timeout=CONNECT_TIMEOUT)
if response.status_code == requests.codes.not_found:
_LOGGING.debug('Using alternate triggers URL.')
url = '%s/Event/triggers' % self.root_url
response = self.hik_request.get(url)
except (requests.exceptions.RequestException,
requests.exceptions.ConnectionError) as err:
_LOGGING.error('Unable to fetch events, error: %s', err)
return None
if response.status_code != 200:
return None
try:
content = ET.fromstring(response.text)
if content[0].find(self.element_query('EventTrigger')):
event_xml = content[0].findall(
self.element_query('EventTrigger'))
elif content.find(self.element_query('EventTrigger')):
event_xml = content.findall(
self.element_query('EventTrigger'))
for eventtrigger in event_xml:
ettype = eventtrigger.find(self.element_query('eventType'))
if ettype is None:
break
etnotify = eventtrigger.find(
self.element_query('EventTriggerNotificationList'))
etchannel = None
etchannel_num = 0
for node_name in CHANNEL_NAMES:
etchannel = eventtrigger.find(
self.element_query(node_name))
if etchannel is not None:
try:
etchannel_num = int(etchannel.text)
if etchannel_num > 1:
nvrflag = True
break
except ValueError:
pass
if etnotify:
for notifytrigger in etnotify:
ntype = notifytrigger.find(
self.element_query('notificationMethod'))
if ntype.text == 'center' or ntype.text == 'HTTP':
events.setdefault(ettype.text, []) \
.append(etchannel_num)
except (AttributeError, ET.ParseError) as err:
_LOGGING.error(
'There was a problem finding an element: %s', err)
return None
if nvrflag:
self.device_type = NVR_DEVICE
else:
self.device_type = CAM_DEVICE
_LOGGING.debug('Processed %s as %s Device.',
self.cam_id, self.device_type)
_LOGGING.debug('Found events: %s', events)
self.hik_request.close()
return events |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_device_info'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '18', '22', '202', '222', '242']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'device_info'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '13', 'type': 'binary_operator', 'children': ['14', '15'], 'value': '%'},{'id': '14', 'type': 'string', 'children': [], 'value': "'%s/ISAPI/System/deviceInfo'"},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'root_url'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'using_digest'},{'id': '21', 'type': 'False', 'children': []},{'id': '22', 'type': 'try_statement', 'children': ['23', '176']},{'id': '23', 'type': 'block', 'children': ['24', '38', '87']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '27', 'type': 'call', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'hik_request'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'CONNECT_TIMEOUT'},{'id': '38', 'type': 'if_statement', 'children': ['39', '48']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '43'], 'value': '=='},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '43', 'type': 'attribute', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'unauthorized'},{'id': '48', 'type': 'block', 'children': ['49', '56', '72', '76']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'string', 'children': [], 'value': "'Basic authentication failed. Using digest.'"},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '63']},{'id': '58', 'type': 'attribute', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'hik_request'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'HTTPDigestAuth'},{'id': '65', 'type': 'argument_list', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'usr'},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'pwd'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'using_digest'},{'id': '75', 'type': 'True', 'children': []},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'response'},{'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': 'hik_request'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '87', 'type': 'if_statement', 'children': ['88', '97']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '92'], 'value': '=='},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '92', 'type': 'attribute', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'not_found'},{'id': '97', 'type': 'block', 'children': ['98', '105', '113', '124']},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': "'Using alternate deviceInfo URL.'"},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '%'},{'id': '109', 'type': 'string', 'children': [], 'value': "'%s/System/deviceInfo'"},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'root_url'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '116', 'type': 'call', 'children': ['117', '122']},{'id': '117', 'type': 'attribute', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'hik_request'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '124', 'type': 'if_statement', 'children': ['125', '137']},{'id': '125', 'type': 'boolean_operator', 'children': ['126', '128'], 'value': 'and'},{'id': '126', 'type': 'not_operator', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'using_digest'},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '132'], 'value': '=='},{'id': '129', 'type': 'attribute', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'unauthorized'},{'id': '137', 'type': 'block', 'children': ['138', '145', '161', '165']},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'call', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '143', 'type': 'argument_list', 'children': ['144']},{'id': '144', 'type': 'string', 'children': [], 'value': "'Basic authentication failed. Using digest.'"},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '152']},{'id': '147', 'type': 'attribute', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'hik_request'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'auth'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'HTTPDigestAuth'},{'id': '154', 'type': 'argument_list', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'usr'},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'pwd'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'using_digest'},{'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': 'response'},{'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': 'hik_request'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '176', 'type': 'except_clause', 'children': ['177', '191']},{'id': '177', 'type': 'as_pattern', 'children': ['178', '189']},{'id': '178', 'type': 'tuple', 'children': ['179', '184']},{'id': '179', 'type': 'attribute', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'RequestException'},{'id': '184', 'type': 'attribute', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'},{'id': '189', 'type': 'as_pattern_target', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '191', 'type': 'block', 'children': ['192', '200']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'call', 'children': ['194', '197']},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '197', 'type': 'argument_list', 'children': ['198', '199']},{'id': '198', 'type': 'string', 'children': [], 'value': "'Unable to fetch deviceInfo, error: %s'"},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '200', 'type': 'return_statement', 'children': ['201']},{'id': '201', 'type': 'None', 'children': []},{'id': '202', 'type': 'if_statement', 'children': ['203', '212']},{'id': '203', 'type': 'comparison_operator', 'children': ['204', '207'], 'value': '=='},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '207', 'type': 'attribute', 'children': ['208', '211']},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'unauthorized'},{'id': '212', 'type': 'block', 'children': ['213', '220']},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'string', 'children': [], 'value': "'Authentication failed'"},{'id': '220', 'type': 'return_statement', 'children': ['221']},{'id': '221', 'type': 'None', 'children': []},{'id': '222', 'type': 'if_statement', 'children': ['223', '232']},{'id': '223', 'type': 'comparison_operator', 'children': ['224', '227'], 'value': '!='},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '227', 'type': 'attribute', 'children': ['228', '231']},{'id': '228', 'type': 'attribute', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '232', 'type': 'block', 'children': ['233', '240']},{'id': '233', 'type': 'expression_statement', 'children': ['234']},{'id': '234', 'type': 'call', 'children': ['235', '238']},{'id': '235', 'type': 'attribute', 'children': ['236', '237']},{'id': '236', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '238', 'type': 'argument_list', 'children': ['239']},{'id': '239', 'type': 'string', 'children': [], 'value': "'Unable to fetch device info.'"},{'id': '240', 'type': 'return_statement', 'children': ['241']},{'id': '241', 'type': 'None', 'children': []},{'id': '242', 'type': 'try_statement', 'children': ['243', '324']},{'id': '243', 'type': 'block', 'children': ['244', '255', '273', '287', '297', '322']},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '247', 'type': 'call', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'ET'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'fromstring'},{'id': '251', 'type': 'argument_list', 'children': ['252']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'assignment', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'nmsp'},{'id': '258', 'type': 'call', 'children': ['259', '271']},{'id': '259', 'type': 'attribute', 'children': ['260', '270']},{'id': '260', 'type': 'subscript', 'children': ['261', '269']},{'id': '261', 'type': 'call', 'children': ['262', '267']},{'id': '262', 'type': 'attribute', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '267', 'type': 'argument_list', 'children': ['268']},{'id': '268', 'type': 'string', 'children': [], 'value': "'}'"},{'id': '269', 'type': 'integer', 'children': [], 'value': '0'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'string', 'children': [], 'value': "'{'"},{'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': 'namespace'},{'id': '278', 'type': 'conditional_expression', 'children': ['279', '280', '286'], 'value': 'if'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'nmsp'},{'id': '280', 'type': 'call', 'children': ['281', '284']},{'id': '281', 'type': 'attribute', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'nmsp'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '284', 'type': 'argument_list', 'children': ['285']},{'id': '285', 'type': 'string', 'children': [], 'value': "'http'"},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'XML_NAMESPACE'},{'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': '_LOGGING'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '292', 'type': 'argument_list', 'children': ['293', '294']},{'id': '293', 'type': 'string', 'children': [], 'value': "'Using Namespace: %s'"},{'id': '294', 'type': 'attribute', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '296', 'type': 'identifier', 'children': [], 'value': 'namespace'},{'id': '297', 'type': 'for_statement', 'children': ['298', '299', '300']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '300', 'type': 'block', 'children': ['301', '314']},{'id': '301', 'type': 'expression_statement', 'children': ['302']},{'id': '302', 'type': 'assignment', 'children': ['303', '304']},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '304', 'type': 'subscript', 'children': ['305', '313']},{'id': '305', 'type': 'call', 'children': ['306', '311']},{'id': '306', 'type': 'attribute', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '311', 'type': 'argument_list', 'children': ['312']},{'id': '312', 'type': 'string', 'children': [], 'value': "'}'"},{'id': '313', 'type': 'integer', 'children': [], 'value': '1'},{'id': '314', 'type': 'expression_statement', 'children': ['315']},{'id': '315', 'type': 'assignment', 'children': ['316', '319']},{'id': '316', 'type': 'subscript', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'device_info'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '322', 'type': 'return_statement', 'children': ['323']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'device_info'},{'id': '324', 'type': 'except_clause', 'children': ['325', '329']},{'id': '325', 'type': 'as_pattern', 'children': ['326', '327']},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '327', 'type': 'as_pattern_target', 'children': ['328']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '329', 'type': 'block', 'children': ['330', '340', '348']},{'id': '330', 'type': 'expression_statement', 'children': ['331']},{'id': '331', 'type': 'call', 'children': ['332', '335']},{'id': '332', 'type': 'attribute', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '334', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '335', 'type': 'argument_list', 'children': ['336', '337']},{'id': '336', 'type': 'string', 'children': [], 'value': "'Entire response: %s'"},{'id': '337', 'type': 'attribute', 'children': ['338', '339']},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'response'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '340', 'type': 'expression_statement', 'children': ['341']},{'id': '341', 'type': 'call', 'children': ['342', '345']},{'id': '342', 'type': 'attribute', 'children': ['343', '344']},{'id': '343', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'error'},{'id': '345', 'type': 'argument_list', 'children': ['346', '347']},{'id': '346', 'type': 'string', 'children': [], 'value': "'There was a problem: %s'"},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '348', 'type': 'return_statement', 'children': ['349']},{'id': '349', 'type': 'None', 'children': []} | def get_device_info(self):
device_info = {}
url = '%s/ISAPI/System/deviceInfo' % self.root_url
using_digest = False
try:
response = self.hik_request.get(url, timeout=CONNECT_TIMEOUT)
if response.status_code == requests.codes.unauthorized:
_LOGGING.debug('Basic authentication failed. Using digest.')
self.hik_request.auth = HTTPDigestAuth(self.usr, self.pwd)
using_digest = True
response = self.hik_request.get(url)
if response.status_code == requests.codes.not_found:
_LOGGING.debug('Using alternate deviceInfo URL.')
url = '%s/System/deviceInfo' % self.root_url
response = self.hik_request.get(url)
if not using_digest and response.status_code == requests.codes.unauthorized:
_LOGGING.debug('Basic authentication failed. Using digest.')
self.hik_request.auth = HTTPDigestAuth(self.usr, self.pwd)
using_digest = True
response = self.hik_request.get(url)
except (requests.exceptions.RequestException,
requests.exceptions.ConnectionError) as err:
_LOGGING.error('Unable to fetch deviceInfo, error: %s', err)
return None
if response.status_code == requests.codes.unauthorized:
_LOGGING.error('Authentication failed')
return None
if response.status_code != requests.codes.ok:
_LOGGING.debug('Unable to fetch device info.')
return None
try:
tree = ET.fromstring(response.text)
nmsp = tree.tag.split('}')[0].strip('{')
self.namespace = nmsp if nmsp.startswith('http') else XML_NAMESPACE
_LOGGING.debug('Using Namespace: %s', self.namespace)
for item in tree:
tag = item.tag.split('}')[1]
device_info[tag] = item.text
return device_info
except AttributeError as err:
_LOGGING.error('Entire response: %s', response.text)
_LOGGING.error('There was a problem: %s', err)
return None |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'alert_stream'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'reset_event'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'kill_event'},{'id': '7', 'type': 'block', 'children': ['8', '21', '25', '29', '33', '41']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '13', 'type': 'argument_list', 'children': ['14', '15', '18']},{'id': '14', 'type': 'string', 'children': [], 'value': "'Stream Thread Started: %s, %s'"},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'cam_id'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'start_event'},{'id': '24', 'type': 'False', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'parse_string'},{'id': '28', 'type': 'string', 'children': [], 'value': '""'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'fail_count'},{'id': '32', 'type': 'integer', 'children': [], 'value': '0'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '%'},{'id': '37', 'type': 'string', 'children': [], 'value': "'%s/ISAPI/Event/notification/alertStream'"},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'root_url'},{'id': '41', 'type': 'while_statement', 'children': ['42', '43']},{'id': '42', 'type': 'True', 'children': []},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'try_statement', 'children': ['45', '301']},{'id': '45', 'type': 'block', 'children': ['46', '65', '98', '138', '255']},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '49', 'type': 'call', 'children': ['50', '55']},{'id': '50', 'type': 'attribute', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'hik_request'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57', '60']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '59', 'type': 'True', 'children': []},{'id': '60', 'type': 'keyword_argument', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'timeout'},{'id': '62', 'type': 'tuple', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'CONNECT_TIMEOUT'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'READ_TIMEOUT'},{'id': '65', 'type': 'if_statement', 'children': ['66', '75']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '70'], 'value': '=='},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '70', 'type': 'attribute', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'not_found'},{'id': '75', 'type': 'block', 'children': ['76', '84']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '%'},{'id': '80', 'type': 'string', 'children': [], 'value': "'%s/Event/notification/alertStream'"},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'root_url'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '87', 'type': 'call', 'children': ['88', '93']},{'id': '88', 'type': 'attribute', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'hik_request'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '93', 'type': 'argument_list', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '97', 'type': 'True', 'children': []},{'id': '98', 'type': 'if_statement', 'children': ['99', '108', '114']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '103'], 'value': '!='},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'status_code'},{'id': '103', 'type': 'attribute', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'codes'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'ok'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'raise_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'string', 'children': [], 'value': "'Connection unsucessful.'"},{'id': '114', 'type': 'else_clause', 'children': ['115']},{'id': '115', 'type': 'block', 'children': ['116', '126', '130']},{'id': '116', 'type': 'expression_statement', 'children': ['117']},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'string', 'children': [], 'value': "'%s Connection Successful.'"},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'assignment', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'fail_count'},{'id': '129', 'type': 'integer', 'children': [], 'value': '0'},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'call', 'children': ['132', '137']},{'id': '132', 'type': 'attribute', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'watchdog'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '137', 'type': 'argument_list', 'children': []},{'id': '138', 'type': 'for_statement', 'children': ['139', '140', '145']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '140', 'type': 'call', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'iter_lines'},{'id': '144', 'type': 'argument_list', 'children': []},{'id': '145', 'type': 'block', 'children': ['146', '235']},{'id': '146', 'type': 'if_statement', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '148', 'type': 'block', 'children': ['149', '159']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'str_line'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'line'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158']},{'id': '157', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '158', 'type': 'string', 'children': [], 'value': '"ignore"'},{'id': '159', 'type': 'if_statement', 'children': ['160', '169', '178', '226']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '167'], 'value': '!='},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'str_line'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'string', 'children': [], 'value': "'<EventNotificationAlert'"},{'id': '167', 'type': 'unary_operator', 'children': ['168'], 'value': '-'},{'id': '168', 'type': 'integer', 'children': [], 'value': '1'},{'id': '169', 'type': 'block', 'children': ['170', '174']},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'start_event'},{'id': '173', 'type': 'True', 'children': []},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'augmented_assignment', 'children': ['176', '177'], 'value': '+='},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'parse_string'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'str_line'},{'id': '178', 'type': 'elif_clause', 'children': ['179', '188']},{'id': '179', 'type': 'comparison_operator', 'children': ['180', '186'], 'value': '!='},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'str_line'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'string', 'children': [], 'value': "'</EventNotificationAlert>'"},{'id': '186', 'type': 'unary_operator', 'children': ['187'], 'value': '-'},{'id': '187', 'type': 'integer', 'children': [], 'value': '1'},{'id': '188', 'type': 'block', 'children': ['189', '193', '197']},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'augmented_assignment', 'children': ['191', '192'], 'value': '+='},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'parse_string'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'str_line'},{'id': '193', 'type': 'expression_statement', 'children': ['194']},{'id': '194', 'type': 'assignment', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'start_event'},{'id': '196', 'type': 'False', 'children': []},{'id': '197', 'type': 'if_statement', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'parse_string'},{'id': '199', 'type': 'block', 'children': ['200', '209', '216', '222']},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'ET'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'fromstring'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'parse_string'},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'process_stream'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '216', 'type': 'expression_statement', 'children': ['217']},{'id': '217', 'type': 'call', 'children': ['218', '221']},{'id': '218', 'type': 'attribute', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'update_stale'},{'id': '221', 'type': 'argument_list', 'children': []},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'parse_string'},{'id': '225', 'type': 'string', 'children': [], 'value': '""'},{'id': '226', 'type': 'else_clause', 'children': ['227']},{'id': '227', 'type': 'block', 'children': ['228']},{'id': '228', 'type': 'if_statement', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'start_event'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'augmented_assignment', 'children': ['233', '234'], 'value': '+='},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'parse_string'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'str_line'},{'id': '235', 'type': 'if_statement', 'children': ['236', '241', '243']},{'id': '236', 'type': 'call', 'children': ['237', '240']},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'kill_event'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'is_set'},{'id': '240', 'type': 'argument_list', 'children': []},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'break_statement', 'children': []},{'id': '243', 'type': 'elif_clause', 'children': ['244', '249']},{'id': '244', 'type': 'call', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'reset_event'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'is_set'},{'id': '248', 'type': 'argument_list', 'children': []},{'id': '249', 'type': 'block', 'children': ['250']},{'id': '250', 'type': 'raise_statement', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'string', 'children': [], 'value': "'Watchdog failed.'"},{'id': '255', 'type': 'if_statement', 'children': ['256', '261', '289']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'kill_event'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'is_set'},{'id': '260', 'type': 'argument_list', 'children': []},{'id': '261', 'type': 'block', 'children': ['262', '272', '280', '288']},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '267', 'type': 'argument_list', 'children': ['268', '269']},{'id': '268', 'type': 'string', 'children': [], 'value': "'Stopping event stream thread for %s'"},{'id': '269', 'type': 'attribute', 'children': ['270', '271']},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'call', 'children': ['274', '279']},{'id': '274', 'type': 'attribute', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'watchdog'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '279', 'type': 'argument_list', 'children': []},{'id': '280', 'type': 'expression_statement', 'children': ['281']},{'id': '281', 'type': 'call', 'children': ['282', '287']},{'id': '282', 'type': 'attribute', 'children': ['283', '286']},{'id': '283', 'type': 'attribute', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'hik_request'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '287', 'type': 'argument_list', 'children': []},{'id': '288', 'type': 'return_statement', 'children': []},{'id': '289', 'type': 'elif_clause', 'children': ['290', '295']},{'id': '290', 'type': 'call', 'children': ['291', '294']},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'reset_event'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'is_set'},{'id': '294', 'type': 'argument_list', 'children': []},{'id': '295', 'type': 'block', 'children': ['296']},{'id': '296', 'type': 'raise_statement', 'children': ['297']},{'id': '297', 'type': 'call', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '299', 'type': 'argument_list', 'children': ['300']},{'id': '300', 'type': 'string', 'children': [], 'value': "'Watchdog failed.'"},{'id': '301', 'type': 'except_clause', 'children': ['302', '317']},{'id': '302', 'type': 'as_pattern', 'children': ['303', '315']},{'id': '303', 'type': 'tuple', 'children': ['304', '305', '310']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '305', 'type': 'attribute', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'ConnectionError'},{'id': '310', 'type': 'attribute', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'requests'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'exceptions'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'ChunkedEncodingError'},{'id': '315', 'type': 'as_pattern_target', 'children': ['316']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '317', 'type': 'block', 'children': ['318', '322', '328', '346', '350', '358', '366', '373', '379', '388']},{'id': '318', 'type': 'expression_statement', 'children': ['319']},{'id': '319', 'type': 'augmented_assignment', 'children': ['320', '321'], 'value': '+='},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'fail_count'},{'id': '321', 'type': 'integer', 'children': [], 'value': '1'},{'id': '322', 'type': 'expression_statement', 'children': ['323']},{'id': '323', 'type': 'call', 'children': ['324', '327']},{'id': '324', 'type': 'attribute', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'reset_event'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '327', 'type': 'argument_list', 'children': []},{'id': '328', 'type': 'expression_statement', 'children': ['329']},{'id': '329', 'type': 'call', 'children': ['330', '333']},{'id': '330', 'type': 'attribute', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': '_LOGGING'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'warning'},{'id': '333', 'type': 'argument_list', 'children': ['334', '335', '338', '339', '345']},{'id': '334', 'type': 'string', 'children': [], 'value': "'%s Connection Failed (count=%d). Waiting %ss. Err: %s'"},{'id': '335', 'type': 'attribute', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'fail_count'},{'id': '339', 'type': 'binary_operator', 'children': ['340', '344'], 'value': '+'},{'id': '340', 'type': '()', 'children': ['341']},{'id': '341', 'type': 'binary_operator', 'children': ['342', '343'], 'value': '*'},{'id': '342', 'type': 'identifier', 'children': [], 'value': 'fail_count'},{'id': '343', 'type': 'integer', 'children': [], 'value': '5'},{'id': '344', 'type': 'integer', 'children': [], 'value': '5'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'err'},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'assignment', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'parse_string'},{'id': '349', 'type': 'string', 'children': [], 'value': '""'},{'id': '350', 'type': 'expression_statement', 'children': ['351']},{'id': '351', 'type': 'call', 'children': ['352', '357']},{'id': '352', 'type': 'attribute', 'children': ['353', '356']},{'id': '353', 'type': 'attribute', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'watchdog'},{'id': '356', 'type': 'identifier', 'children': [], 'value': 'stop'},{'id': '357', 'type': 'argument_list', 'children': []},{'id': '358', 'type': 'expression_statement', 'children': ['359']},{'id': '359', 'type': 'call', 'children': ['360', '365']},{'id': '360', 'type': 'attribute', 'children': ['361', '364']},{'id': '361', 'type': 'attribute', 'children': ['362', '363']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'hik_request'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'close'},{'id': '365', 'type': 'argument_list', 'children': []},{'id': '366', 'type': 'expression_statement', 'children': ['367']},{'id': '367', 'type': 'call', 'children': ['368', '371']},{'id': '368', 'type': 'attribute', 'children': ['369', '370']},{'id': '369', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '371', 'type': 'argument_list', 'children': ['372']},{'id': '372', 'type': 'integer', 'children': [], 'value': '5'},{'id': '373', 'type': 'expression_statement', 'children': ['374']},{'id': '374', 'type': 'call', 'children': ['375', '378']},{'id': '375', 'type': 'attribute', 'children': ['376', '377']},{'id': '376', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '377', 'type': 'identifier', 'children': [], 'value': 'update_stale'},{'id': '378', 'type': 'argument_list', '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': 'time'},{'id': '383', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '384', 'type': 'argument_list', 'children': ['385']},{'id': '385', 'type': 'binary_operator', 'children': ['386', '387'], 'value': '*'},{'id': '386', 'type': 'identifier', 'children': [], 'value': 'fail_count'},{'id': '387', 'type': 'integer', 'children': [], 'value': '5'},{'id': '388', 'type': 'continue_statement', 'children': []} | def alert_stream(self, reset_event, kill_event):
_LOGGING.debug('Stream Thread Started: %s, %s', self.name, self.cam_id)
start_event = False
parse_string = ""
fail_count = 0
url = '%s/ISAPI/Event/notification/alertStream' % self.root_url
while True:
try:
stream = self.hik_request.get(url, stream=True,
timeout=(CONNECT_TIMEOUT,
READ_TIMEOUT))
if stream.status_code == requests.codes.not_found:
url = '%s/Event/notification/alertStream' % self.root_url
stream = self.hik_request.get(url, stream=True)
if stream.status_code != requests.codes.ok:
raise ValueError('Connection unsucessful.')
else:
_LOGGING.debug('%s Connection Successful.', self.name)
fail_count = 0
self.watchdog.start()
for line in stream.iter_lines():
if line:
str_line = line.decode("utf-8", "ignore")
if str_line.find('<EventNotificationAlert') != -1:
start_event = True
parse_string += str_line
elif str_line.find('</EventNotificationAlert>') != -1:
parse_string += str_line
start_event = False
if parse_string:
tree = ET.fromstring(parse_string)
self.process_stream(tree)
self.update_stale()
parse_string = ""
else:
if start_event:
parse_string += str_line
if kill_event.is_set():
break
elif reset_event.is_set():
raise ValueError('Watchdog failed.')
if kill_event.is_set():
_LOGGING.debug('Stopping event stream thread for %s',
self.name)
self.watchdog.stop()
self.hik_request.close()
return
elif reset_event.is_set():
raise ValueError('Watchdog failed.')
except (ValueError,
requests.exceptions.ConnectionError,
requests.exceptions.ChunkedEncodingError) as err:
fail_count += 1
reset_event.clear()
_LOGGING.warning('%s Connection Failed (count=%d). Waiting %ss. Err: %s',
self.name, fail_count, (fail_count * 5) + 5, err)
parse_string = ""
self.watchdog.stop()
self.hik_request.close()
time.sleep(5)
self.update_stale()
time.sleep(fail_count * 5)
continue |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'construct_request'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'ticker'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'date_from'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'date_to'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'block', 'children': ['21', '55', '98', '163', '174']},{'id': '21', 'type': 'if_statement', 'children': ['22', '27', '32', '48']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ticker'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ticker'},{'id': '32', 'type': 'elif_clause', 'children': ['33', '38']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ticker'},{'id': '37', 'type': 'string', 'children': [], 'value': "'__len__'"},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "','"},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'ticker'},{'id': '48', 'type': 'else_clause', 'children': ['49']},{'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': "'ticker should be either string or list/array of strings'"},{'id': '55', 'type': 'if_statement', 'children': ['56', '59']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'is'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'if_statement', 'children': ['61', '66', '73']},{'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': 'fields'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'augmented_assignment', 'children': ['69', '70'], 'value': '+='},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '+'},{'id': '71', 'type': 'string', 'children': [], 'value': "'~='"},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '73', 'type': 'elif_clause', 'children': ['74', '86']},{'id': '74', 'type': 'boolean_operator', 'children': ['75', '80'], 'value': 'and'},{'id': '75', 'type': 'call', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '80', 'type': 'comparison_operator', 'children': ['81', '85'], 'value': '>'},{'id': '81', 'type': 'call', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '83', 'type': 'argument_list', 'children': ['84']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '85', 'type': 'integer', 'children': [], 'value': '0'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'augmented_assignment', 'children': ['89', '90'], 'value': '+='},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '+'},{'id': '91', 'type': 'string', 'children': [], 'value': "'~='"},{'id': '92', 'type': 'call', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'string', 'children': [], 'value': "','"},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '98', 'type': 'if_statement', 'children': ['99', '102', '119']},{'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '101', 'type': 'None', 'children': []},{'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': 'request'},{'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '+'},{'id': '107', 'type': 'string', 'children': [], 'value': "'~@'"},{'id': '108', 'type': 'call', 'children': ['109', '117']},{'id': '109', 'type': 'attribute', 'children': ['110', '116']},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'to_datetime'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'date'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'string', 'children': [], 'value': "'%Y-%m-%d'"},{'id': '119', 'type': 'else_clause', 'children': ['120']},{'id': '120', 'type': 'block', 'children': ['121', '142']},{'id': '121', 'type': 'if_statement', 'children': ['122', '125']},{'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'is'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'date_from'},{'id': '124', 'type': 'None', 'children': []},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'expression_statement', 'children': ['127']},{'id': '127', 'type': 'augmented_assignment', 'children': ['128', '129'], 'value': '+='},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '+'},{'id': '130', 'type': 'string', 'children': [], 'value': "'~'"},{'id': '131', 'type': 'call', 'children': ['132', '140']},{'id': '132', 'type': 'attribute', 'children': ['133', '139']},{'id': '133', 'type': 'call', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'to_datetime'},{'id': '137', 'type': 'argument_list', 'children': ['138']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'date_from'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'string', 'children': [], 'value': "'%Y-%m-%d'"},{'id': '142', 'type': 'if_statement', 'children': ['143', '146']},{'id': '143', 'type': 'comparison_operator', 'children': ['144', '145'], 'value': 'is'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'date_to'},{'id': '145', 'type': 'None', 'children': []},{'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': 'request'},{'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '+'},{'id': '151', 'type': 'string', 'children': [], 'value': "'~:'"},{'id': '152', 'type': 'call', 'children': ['153', '161']},{'id': '153', 'type': 'attribute', 'children': ['154', '160']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'to_datetime'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'date_to'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'strftime'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'string', 'children': [], 'value': "'%Y-%m-%d'"},{'id': '163', 'type': 'if_statement', 'children': ['164', '167']},{'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': 'is'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '166', 'type': 'None', 'children': []},{'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': 'request'},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '+'},{'id': '172', 'type': 'string', 'children': [], 'value': "'~'"},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'freq'},{'id': '174', 'type': 'return_statement', 'children': ['175']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'request'} | def construct_request(ticker, fields=None, date=None,
date_from=None, date_to=None, freq=None):
if isinstance(ticker, basestring):
request = ticker
elif hasattr(ticker, '__len__'):
request = ','.join(ticker)
else:
raise ValueError('ticker should be either string or list/array of strings')
if fields is not None:
if isinstance(fields, basestring):
request += '~=' + fields
elif isinstance(fields, list) and len(fields) > 0:
request += '~=' + ','.join(fields)
if date is not None:
request += '~@' + pd.to_datetime(date).strftime('%Y-%m-%d')
else:
if date_from is not None:
request += '~' + pd.to_datetime(date_from).strftime('%Y-%m-%d')
if date_to is not None:
request += '~:' + pd.to_datetime(date_to).strftime('%Y-%m-%d')
if freq is not None:
request += '~' + freq
return request |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '9', 'type': 'unary_operator', 'children': ['10'], 'value': '-'},{'id': '10', 'type': 'integer', 'children': [], 'value': '1'},{'id': '11', 'type': 'block', 'children': ['12', '29', '37', '53', '72', '139', '152', '162', '184']},{'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': 'value'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'ElementProxy'},{'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': 'value'},{'id': '22', 'type': 'call', 'children': ['23', '28']},{'id': '23', 'type': 'attribute', 'children': ['24', '27']},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'to_er7'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '40', 'type': 'conditional_expression', 'children': ['41', '42', '45'], 'value': 'if'},{'id': '41', 'type': 'None', 'children': []},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '44', 'type': 'None', 'children': []},{'id': '45', 'type': 'call', 'children': ['46', '51']},{'id': '46', 'type': 'attribute', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'find_child_reference'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '58']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'child_ref'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'child_name'},{'id': '58', 'type': 'conditional_expression', 'children': ['59', '62', '65'], 'value': 'if'},{'id': '59', 'type': 'tuple', 'children': ['60', '61']},{'id': '60', 'type': 'None', 'children': []},{'id': '61', 'type': 'None', 'children': []},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '64', 'type': 'None', 'children': []},{'id': '65', 'type': 'tuple', 'children': ['66', '69']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '68', 'type': 'string', 'children': [], 'value': "'ref'"},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '71', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '72', 'type': 'if_statement', 'children': ['73', '78', '96', '107', '131']},{'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': 'value'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'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': 'child'},{'id': '82', 'type': 'call', 'children': ['83', '88']},{'id': '83', 'type': 'attribute', 'children': ['84', '87']},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'parse_child'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90', '93']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'child_name'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'child_name'},{'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'child_ref'},{'id': '96', 'type': 'elif_clause', 'children': ['97', '102']},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'Element'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '107', 'type': 'elif_clause', 'children': ['108', '113']},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '110', 'type': 'argument_list', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'BaseDataType'},{'id': '113', 'type': 'block', 'children': ['114', '125']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'assignment', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '117', 'type': 'call', 'children': ['118', '121']},{'id': '118', 'type': 'attribute', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'create_element'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123', '124']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '123', 'type': 'False', 'children': []},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'reference'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'assignment', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '131', 'type': 'else_clause', 'children': ['132']},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'raise_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'ChildNotValid'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'child_name'},{'id': '139', 'type': 'if_statement', 'children': ['140', '145']},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '144'], 'value': '!='},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'child_name'},{'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': 'ChildNotValid'},{'id': '149', 'type': 'argument_list', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'child_name'},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'child_to_remove'},{'id': '155', 'type': 'call', 'children': ['156', '159']},{'id': '156', 'type': 'attribute', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'child_at_index'},{'id': '159', 'type': 'argument_list', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'child_name'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '162', 'type': 'if_statement', 'children': ['163', '166', '174']},{'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': 'is'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'child_to_remove'},{'id': '165', 'type': 'None', 'children': []},{'id': '166', 'type': 'block', 'children': ['167']},{'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': 'self'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '174', 'type': 'else_clause', 'children': ['175']},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'replace_child'},{'id': '181', 'type': 'argument_list', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'child_to_remove'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '191']},{'id': '186', 'type': 'attribute', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'set_parent_to_traversal'},{'id': '191', 'type': 'argument_list', 'children': []} | def set(self, name, value, index=-1):
if isinstance(value, ElementProxy):
value = value[0].to_er7()
name = name.upper()
reference = None if name is None else self.element.find_child_reference(name)
child_ref, child_name = (None, None) if reference is None else (reference['ref'], reference['name'])
if isinstance(value, basestring):
child = self.element.parse_child(value, child_name=child_name, reference=child_ref)
elif isinstance(value, Element):
child = value
elif isinstance(value, BaseDataType):
child = self.create_element(name, False, reference)
child.value = value
else:
raise ChildNotValid(value, child_name)
if child.name != child_name:
raise ChildNotValid(value, child_name)
child_to_remove = self.child_at_index(child_name, index)
if child_to_remove is None:
self.append(child)
else:
self.replace_child(child_to_remove, child)
self.element.set_parent_to_traversal() |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'init_app'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'config_prefix'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '25', '35', '54', '61', '80', '93', '108', '122', '136', '241', '255', '296', '305', '346', '354', '364']},{'id': '10', 'type': 'if_statement', 'children': ['11', '16']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'not'},{'id': '12', 'type': 'string', 'children': [], 'value': "'redis'"},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'extensions'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '24']},{'id': '19', 'type': 'subscript', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'extensions'},{'id': '23', 'type': 'string', 'children': [], 'value': "'redis'"},{'id': '24', 'type': 'dictionary', 'children': []},{'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': 'config_prefix'},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'config_prefix'},{'id': '32', 'type': 'boolean_operator', 'children': ['33', '34'], 'value': 'or'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'config_prefix'},{'id': '34', 'type': 'string', 'children': [], 'value': "'REDIS'"},{'id': '35', 'type': 'if_statement', 'children': ['36', '43']},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '38'], 'value': 'in'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'config_prefix'},{'id': '38', 'type': 'subscript', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'extensions'},{'id': '42', 'type': 'string', 'children': [], 'value': "'redis'"},{'id': '43', 'type': 'block', 'children': ['44']},{'id': '44', 'type': 'raise_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'Already registered config prefix {0!r}.'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'config_prefix'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'converters'},{'id': '57', 'type': 'dictionary', 'children': ['58']},{'id': '58', 'type': 'pair', 'children': ['59', '60']},{'id': '59', 'type': 'string', 'children': [], 'value': "'port'"},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'convert'},{'id': '64', 'type': 'lambda', 'children': ['65', '68']},{'id': '65', 'type': 'lambda_parameters', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '68', 'type': '()', 'children': ['69']},{'id': '69', 'type': 'conditional_expression', 'children': ['70', '76', '79'], 'value': 'if'},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'subscript', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'converters'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'in'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'converters'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '83', 'type': 'lambda', 'children': ['84', '86']},{'id': '84', 'type': 'lambda_parameters', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'string', 'children': [], 'value': "'{0}_{1}'"},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'config_prefix'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '96', 'type': 'call', 'children': ['97', '102']},{'id': '97', 'type': 'attribute', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '102', 'type': 'argument_list', 'children': ['103', '107']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'string', 'children': [], 'value': "'CLASS'"},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'RedisClass'},{'id': '108', 'type': 'if_statement', 'children': ['109', '114']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'string_types'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'import_string'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'url'},{'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': 'config'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'string', 'children': [], 'value': "'URL'"},{'id': '136', 'type': 'if_statement', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '138', 'type': 'block', 'children': ['139', '148', '157', '170', '185', '198', '211', '223']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'call', 'children': ['141', '146']},{'id': '141', 'type': 'attribute', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'uses_netloc'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'string', 'children': [], 'value': "'redis'"},{'id': '148', 'type': 'expression_statement', 'children': ['149']},{'id': '149', 'type': 'assignment', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'urlparse'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '167']},{'id': '159', 'type': 'subscript', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'string', 'children': [], 'value': "'HOST'"},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'hostname'},{'id': '170', 'type': 'expression_statement', 'children': ['171']},{'id': '171', 'type': 'assignment', 'children': ['172', '180']},{'id': '172', 'type': 'subscript', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'string', 'children': [], 'value': "'PORT'"},{'id': '180', 'type': 'boolean_operator', 'children': ['181', '184'], 'value': 'or'},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '184', 'type': 'integer', 'children': [], 'value': '6379'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '195']},{'id': '187', 'type': 'subscript', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'string', 'children': [], 'value': "'USER'"},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '208']},{'id': '200', 'type': 'subscript', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '204', 'type': 'call', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '206', 'type': 'argument_list', 'children': ['207']},{'id': '207', 'type': 'string', 'children': [], 'value': "'PASSWORD'"},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'url'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'password'},{'id': '211', 'type': 'expression_statement', 'children': ['212']},{'id': '212', 'type': 'assignment', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'db'},{'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': 'url'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '220', 'type': 'argument_list', 'children': ['221', '222']},{'id': '221', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '222', 'type': 'string', 'children': [], 'value': "''"},{'id': '223', 'type': 'expression_statement', 'children': ['224']},{'id': '224', 'type': 'assignment', 'children': ['225', '233']},{'id': '225', 'type': 'subscript', 'children': ['226', '229']},{'id': '226', 'type': 'attribute', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '229', 'type': 'call', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '231', 'type': 'argument_list', 'children': ['232']},{'id': '232', 'type': 'string', 'children': [], 'value': "'DB'"},{'id': '233', 'type': 'conditional_expression', 'children': ['234', '235', '240'], 'value': 'if'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '235', 'type': 'call', 'children': ['236', '239']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '239', 'type': 'argument_list', 'children': []},{'id': '240', 'type': 'None', 'children': []},{'id': '241', 'type': 'expression_statement', 'children': ['242']},{'id': '242', 'type': 'assignment', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '244', 'type': 'call', 'children': ['245', '250']},{'id': '245', 'type': 'attribute', 'children': ['246', '249']},{'id': '246', 'type': 'attribute', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'call', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'string', 'children': [], 'value': "'HOST'"},{'id': '255', 'type': 'if_statement', 'children': ['256', '272']},{'id': '256', 'type': 'boolean_operator', 'children': ['257', '258'], 'value': 'and'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '258', 'type': '()', 'children': ['259']},{'id': '259', 'type': 'boolean_operator', 'children': ['260', '266'], 'value': 'or'},{'id': '260', 'type': 'call', 'children': ['261', '264']},{'id': '261', 'type': 'attribute', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '264', 'type': 'argument_list', 'children': ['265']},{'id': '265', 'type': 'string', 'children': [], 'value': "'file://'"},{'id': '266', 'type': 'call', 'children': ['267', '270']},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '270', 'type': 'argument_list', 'children': ['271']},{'id': '271', 'type': 'string', 'children': [], 'value': "'/'"},{'id': '272', 'type': 'block', 'children': ['273', '285']},{'id': '273', 'type': 'expression_statement', 'children': ['274']},{'id': '274', 'type': 'call', 'children': ['275', '280']},{'id': '275', 'type': 'attribute', 'children': ['276', '279']},{'id': '276', 'type': 'attribute', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'call', 'children': ['282', '283']},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '283', 'type': 'argument_list', 'children': ['284']},{'id': '284', 'type': 'string', 'children': [], 'value': "'HOST'"},{'id': '285', 'type': 'expression_statement', 'children': ['286']},{'id': '286', 'type': 'assignment', 'children': ['287', '295']},{'id': '287', 'type': 'subscript', 'children': ['288', '291']},{'id': '288', 'type': 'attribute', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '291', 'type': 'call', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '293', 'type': 'argument_list', 'children': ['294']},{'id': '294', 'type': 'string', 'children': [], 'value': "'UNIX_SOCKET_PATH'"},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'host'},{'id': '296', 'type': 'expression_statement', 'children': ['297']},{'id': '297', 'type': 'assignment', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '299', 'type': 'call', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '302', 'type': 'identifier', 'children': [], 'value': '_build_connection_args'},{'id': '303', 'type': 'argument_list', 'children': ['304']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '305', 'type': 'expression_statement', 'children': ['306']},{'id': '306', 'type': 'assignment', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '308', 'type': 'call', 'children': ['309', '310']},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '310', 'type': 'argument_list', 'children': ['311']},{'id': '311', 'type': 'list_comprehension', 'children': ['312', '330', '333']},{'id': '312', 'type': 'tuple', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '314', 'type': 'call', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'convert'},{'id': '316', 'type': 'argument_list', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '318', 'type': 'subscript', 'children': ['319', '322']},{'id': '319', 'type': 'attribute', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '322', 'type': 'call', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '324', 'type': 'argument_list', 'children': ['325']},{'id': '325', 'type': 'call', 'children': ['326', '329']},{'id': '326', 'type': 'attribute', 'children': ['327', '328']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '329', 'type': 'argument_list', 'children': []},{'id': '330', 'type': 'for_in_clause', 'children': ['331', '332']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '333', 'type': 'if_clause', 'children': ['334']},{'id': '334', 'type': 'comparison_operator', 'children': ['335', '343'], 'value': 'in'},{'id': '335', 'type': 'call', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '337', 'type': 'argument_list', 'children': ['338']},{'id': '338', 'type': 'call', 'children': ['339', '342']},{'id': '339', 'type': 'attribute', 'children': ['340', '341']},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '342', 'type': 'argument_list', 'children': []},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'assignment', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '349', 'type': 'call', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'klass'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'dictionary_splat', 'children': ['353']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '354', 'type': 'expression_statement', 'children': ['355']},{'id': '355', 'type': 'assignment', 'children': ['356', '363']},{'id': '356', 'type': 'subscript', 'children': ['357', '362']},{'id': '357', 'type': 'subscript', 'children': ['358', '361']},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'extensions'},{'id': '361', 'type': 'string', 'children': [], 'value': "'redis'"},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'config_prefix'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'connection'},{'id': '364', 'type': 'expression_statement', 'children': ['365']},{'id': '365', 'type': 'call', 'children': ['366', '369']},{'id': '366', 'type': 'attribute', 'children': ['367', '368']},{'id': '367', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '368', 'type': 'identifier', 'children': [], 'value': '_include_public_methods'},{'id': '369', 'type': 'argument_list', 'children': ['370']},{'id': '370', 'type': 'identifier', 'children': [], 'value': 'connection'} | def init_app(self, app, config_prefix=None):
if 'redis' not in app.extensions:
app.extensions['redis'] = {}
self.config_prefix = config_prefix = config_prefix or 'REDIS'
if config_prefix in app.extensions['redis']:
raise ValueError('Already registered config prefix {0!r}.'.
format(config_prefix))
converters = {'port': int}
convert = lambda arg, value: (converters[arg](value)
if arg in converters
else value)
key = lambda param: '{0}_{1}'.format(config_prefix, param)
klass = app.config.get(key('CLASS'), RedisClass)
if isinstance(klass, string_types):
klass = import_string(klass)
url = app.config.get(key('URL'))
if url:
urlparse.uses_netloc.append('redis')
url = urlparse.urlparse(url)
app.config[key('HOST')] = url.hostname
app.config[key('PORT')] = url.port or 6379
app.config[key('USER')] = url.username
app.config[key('PASSWORD')] = url.password
db = url.path.replace('/', '')
app.config[key('DB')] = db if db.isdigit() else None
host = app.config.get(key('HOST'))
if host and (host.startswith('file://') or host.startswith('/')):
app.config.pop(key('HOST'))
app.config[key('UNIX_SOCKET_PATH')] = host
args = self._build_connection_args(klass)
kwargs = dict([(arg, convert(arg, app.config[key(arg.upper())]))
for arg in args
if key(arg.upper()) in app.config])
connection = klass(**kwargs)
app.extensions['redis'][config_prefix] = connection
self._include_public_methods(connection) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'ERROR', 'children': ['2', '348']},{'id': '2', 'type': 'function_definition', 'children': ['3', '4', '6']},{'id': '3', 'type': 'function_name', 'children': [], 'value': '__setup_native_run'},{'id': '4', 'type': 'parameters', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '6', 'type': 'block', 'children': ['7', '14', '29', '59', '72', '84', '97', '121', '150', '163', '165', '217', '229', '235', '301']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'vol_opts'},{'id': '12', 'type': 'list', 'children': ['13'], 'value': "['z']"},{'id': '13', 'type': 'string', 'children': [], 'value': "'z'"},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'add_env'},{'id': '19', 'type': 'argument_list', 'children': ['20', '21']},{'id': '20', 'type': 'string', 'children': [], 'value': "'SCUBAINIT_UMASK'"},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'string', 'children': [], 'value': "'{:04o}'"},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'get_umask'},{'id': '28', 'type': 'argument_list', 'children': []},{'id': '29', 'type': 'if_statement', 'children': ['30', '34']},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'as_root'},{'id': '34', 'type': 'block', 'children': ['35', '47']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'add_env'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'string', 'children': [], 'value': "'SCUBAINIT_UID'"},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'getuid'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'add_env'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "'SCUBAINIT_GID'"},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'getgid'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'if_statement', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'add_env'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': "'SCUBAINIT_VERBOSE'"},{'id': '71', 'type': 'integer', 'children': [], 'value': '1'},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'assignment', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'scubainit_cpath'},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'copy_scubadir_file'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'string', 'children': [], 'value': "'scubainit'"},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'scubainit_path'},{'id': '84', 'type': 'for_statement', 'children': ['85', '86', '89']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '86', 'type': 'tuple', 'children': ['87', '88']},{'id': '87', 'type': 'string', 'children': [], 'value': "'root'"},{'id': '88', 'type': 'string', 'children': [], 'value': "'user'"},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': '__generate_hook_script'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '97', 'type': 'if_statement', 'children': ['98', '113']},{'id': '98', 'type': 'boolean_operator', 'children': ['99', '106'], 'value': 'and'},{'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': 'sys'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'stdout'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'isatty'},{'id': '105', 'type': 'argument_list', 'children': []},{'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': 'sys'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'stdin'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'isatty'},{'id': '112', 'type': 'argument_list', 'children': []},{'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': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'add_option'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'string', 'children': [], 'value': "'--tty'"},{'id': '121', 'type': 'try_statement', 'children': ['122', '136']},{'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': 'context'},{'id': '126', 'type': 'call', 'children': ['127', '132']},{'id': '127', 'type': 'attribute', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'process_command'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'user_command'},{'id': '136', 'type': 'except_clause', 'children': ['137', '141']},{'id': '137', 'type': 'as_pattern', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'ConfigError'},{'id': '139', 'type': 'as_pattern_target', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'cfgerr'},{'id': '141', 'type': 'block', 'children': ['142']},{'id': '142', 'type': 'raise_statement', 'children': ['143']},{'id': '143', 'type': 'call', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'ScubaError'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'cfgerr'},{'id': '150', 'type': 'if_statement', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'image_override'},{'id': '154', 'type': 'block', 'children': ['155']},{'id': '155', 'type': 'expression_statement', 'children': ['156']},{'id': '156', 'type': 'assignment', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'image_override'},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'string', 'children': [], 'value': '\'\'\'\n Normally, if the user provides no command to "docker run", the image\'s\n default CMD is run. Because we set the entrypiont, scuba must emulate the\n default behavior itself.\n \'\'\''},{'id': '165', 'type': 'if_statement', 'children': ['166', '170']},{'id': '166', 'type': 'not_operator', 'children': ['167']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'script'},{'id': '170', 'type': 'block', 'children': ['171', '176', '185', '194', '207']},{'id': '171', 'type': 'expression_statement', 'children': ['172']},{'id': '172', 'type': 'call', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'verbose_msg'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'string', 'children': [], 'value': "'No user command; getting command from image'"},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'assignment', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'default_cmd'},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'get_image_command'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '185', 'type': 'if_statement', 'children': ['186', '188']},{'id': '186', 'type': 'not_operator', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'default_cmd'},{'id': '188', 'type': 'block', 'children': ['189']},{'id': '189', 'type': 'raise_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'ScubaError'},{'id': '192', 'type': 'argument_list', 'children': ['193']},{'id': '193', 'type': 'string', 'children': [], 'value': "'No command given and no image-specified command'"},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'call', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'verbose_msg'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'call', 'children': ['199', '202']},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'string', 'children': [], 'value': '\'{} Cmd: "{}"\''},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '202', 'type': 'argument_list', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'default_cmd'},{'id': '207', 'type': 'expression_statement', 'children': ['208']},{'id': '208', 'type': 'assignment', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'script'},{'id': '212', 'type': 'list', 'children': ['213'], 'value': '[shell_quote_cmd(default_cmd)]'},{'id': '213', 'type': 'call', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'shell_quote_cmd'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'default_cmd'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'add_option'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'string', 'children': [], 'value': "'--entrypoint={}'"},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'scubainit_cpath'},{'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': 'self'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'docker_cmd'},{'id': '234', 'type': 'list', 'children': [], 'value': '[]'},{'id': '235', 'type': 'if_statement', 'children': ['236', '241', '258', '281']},{'id': '236', 'type': 'comparison_operator', 'children': ['237', '240'], 'value': 'is'},{'id': '237', 'type': 'attribute', 'children': ['238', '239']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'entrypoint_override'},{'id': '240', 'type': 'None', 'children': []},{'id': '241', 'type': 'block', 'children': ['242']},{'id': '242', 'type': 'if_statement', 'children': ['243', '248']},{'id': '243', 'type': 'comparison_operator', 'children': ['244', '247'], 'value': '!='},{'id': '244', 'type': 'attribute', 'children': ['245', '246']},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'entrypoint_override'},{'id': '247', 'type': 'string', 'children': [], 'value': "''"},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'expression_statement', 'children': ['250']},{'id': '250', 'type': 'assignment', 'children': ['251', '254']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'docker_cmd'},{'id': '254', 'type': 'list', 'children': ['255'], 'value': '[self.entrypoint_override]'},{'id': '255', 'type': 'attribute', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'entrypoint_override'},{'id': '258', 'type': 'elif_clause', 'children': ['259', '264']},{'id': '259', 'type': 'comparison_operator', 'children': ['260', '263'], 'value': 'is'},{'id': '260', 'type': 'attribute', 'children': ['261', '262']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'entrypoint'},{'id': '263', 'type': 'None', 'children': []},{'id': '264', 'type': 'block', 'children': ['265']},{'id': '265', 'type': 'if_statement', 'children': ['266', '271']},{'id': '266', 'type': 'comparison_operator', 'children': ['267', '270'], 'value': '!='},{'id': '267', 'type': 'attribute', 'children': ['268', '269']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'entrypoint'},{'id': '270', 'type': 'string', 'children': [], 'value': "''"},{'id': '271', 'type': 'block', 'children': ['272']},{'id': '272', 'type': 'expression_statement', 'children': ['273']},{'id': '273', 'type': 'assignment', 'children': ['274', '277']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'docker_cmd'},{'id': '277', 'type': 'list', 'children': ['278'], 'value': '[context.entrypoint]'},{'id': '278', 'type': 'attribute', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'entrypoint'},{'id': '281', 'type': 'else_clause', 'children': ['282']},{'id': '282', 'type': 'block', 'children': ['283', '292']},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '286', 'type': 'call', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'get_image_entrypoint'},{'id': '288', 'type': 'argument_list', 'children': ['289']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '292', 'type': 'if_statement', 'children': ['293', '294']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '294', 'type': 'block', 'children': ['295']},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '300']},{'id': '297', 'type': 'attribute', 'children': ['298', '299']},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'docker_cmd'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'ep'},{'id': '301', 'type': 'with_statement', 'children': ['302', '314', '341']},{'id': '302', 'type': 'with_clause', 'children': ['303']},{'id': '303', 'type': 'with_item', 'children': ['304']},{'id': '304', 'type': 'as_pattern', 'children': ['305', '312']},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'open_scubadir_file'},{'id': '309', 'type': 'argument_list', 'children': ['310', '311']},{'id': '310', 'type': 'string', 'children': [], 'value': "'command.sh'"},{'id': '311', 'type': 'string', 'children': [], 'value': "'wt'"},{'id': '312', 'type': 'as_pattern_target', 'children': ['313']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '314', 'type': 'ERROR', 'children': ['315', '325', '326', '327']},{'id': '315', 'type': 'expression_statement', 'children': ['316']},{'id': '316', 'type': 'augmented_assignment', 'children': ['317', '320'], 'value': '+='},{'id': '317', 'type': 'attribute', 'children': ['318', '319']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'docker_cmd'},{'id': '320', 'type': 'list', 'children': ['321', '322'], 'value': "['/bin/sh', f.container_path]"},{'id': '321', 'type': 'string', 'children': [], 'value': "'/bin/sh'"},{'id': '322', 'type': 'attribute', 'children': ['323', '324']},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'container_path'},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'writeln'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '327', 'type': 'comparison_operator', 'children': ['328', '335', '338'], 'value': 'in'},{'id': '328', 'type': 'call', 'children': ['329', '330', '332']},{'id': '329', 'type': 'string', 'children': [], 'value': "'\n writeln(f, '"},{'id': '330', 'type': 'ERROR', 'children': ['331']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'writeln'},{'id': '332', 'type': 'argument_list', 'children': ['333', '334']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '334', 'type': 'string', 'children': [], 'value': "'set -e'"},{'id': '335', 'type': 'ERROR', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'for'},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'script'},{'id': '341', 'type': 'block', 'children': ['342']},{'id': '342', 'type': 'expression_statement', 'children': ['343']},{'id': '343', 'type': 'call', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'writeln'},{'id': '345', 'type': 'argument_list', 'children': ['346', '347']},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '347', 'type': 'identifier', 'children': [], 'value': 'cmd'},{'id': '348', 'type': 'expression_statement', 'children': ['349']},{'id': '349', 'type': 'assignment', 'children': ['350', '353']},{'id': '350', 'type': 'attribute', 'children': ['351', '352']},{'id': '351', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'context'} | def __setup_native_run(self):
self.vol_opts = ['z']
self.add_env('SCUBAINIT_UMASK', '{:04o}'.format(get_umask()))
if not self.as_root:
self.add_env('SCUBAINIT_UID', os.getuid())
self.add_env('SCUBAINIT_GID', os.getgid())
if self.verbose:
self.add_env('SCUBAINIT_VERBOSE', 1)
scubainit_cpath = self.copy_scubadir_file('scubainit', self.scubainit_path)
for name in ('root', 'user', ):
self.__generate_hook_script(name)
if sys.stdout.isatty() and sys.stdin.isatty():
self.add_option('--tty')
try:
context = self.config.process_command(self.user_command)
except ConfigError as cfgerr:
raise ScubaError(str(cfgerr))
if self.image_override:
context.image = self.image_override
'''
Normally, if the user provides no command to "docker run", the image's
default CMD is run. Because we set the entrypiont, scuba must emulate the
default behavior itself.
'''
if not context.script:
verbose_msg('No user command; getting command from image')
default_cmd = get_image_command(context.image)
if not default_cmd:
raise ScubaError('No command given and no image-specified command')
verbose_msg('{} Cmd: "{}"'.format(context.image, default_cmd))
context.script = [shell_quote_cmd(default_cmd)]
self.add_option('--entrypoint={}'.format(scubainit_cpath))
self.docker_cmd = []
if self.entrypoint_override is not None:
if self.entrypoint_override != '':
self.docker_cmd = [self.entrypoint_override]
elif context.entrypoint is not None:
if context.entrypoint != '':
self.docker_cmd = [context.entrypoint]
else:
ep = get_image_entrypoint(context.image)
if ep:
self.docker_cmd = ep
with self.open_scubadir_file('command.sh', 'wt') as f:
self.docker_cmd += ['/bin/sh', f.container_path]
writeln(f, '
writeln(f, '
writeln(f, 'set -e')
for cmd in context.script:
writeln(f, cmd)
self.context = context |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12', '18']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'generic_type', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Sequence'},{'id': '9', 'type': 'type_parameter', 'children': ['10']},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'Record'},{'id': '12', 'type': 'type', 'children': ['13']},{'id': '13', 'type': 'generic_type', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'List'},{'id': '15', 'type': 'type_parameter', 'children': ['16']},{'id': '16', 'type': 'type', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'Record'},{'id': '18', 'type': 'block', 'children': ['19', '21']},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': '"Sort records into a canonical order, suitable for comparison."'},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '24', 'type': 'argument_list', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'records'},{'id': '26', 'type': 'keyword_argument', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '28', 'type': 'identifier', 'children': [], 'value': '_record_key'} | def sort(records: Sequence[Record]) -> List[Record]:
"Sort records into a canonical order, suitable for comparison."
return sorted(records, key=_record_key) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_issubclass_Mapping_covariant'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'subclass'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'superclass'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'bound_Generic'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'bound_typevars'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'bound_typevars_readonly'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'follow_fwd_refs'},{'id': '10', 'type': 'identifier', 'children': [], 'value': '_recursion_check'},{'id': '11', 'type': 'block', 'children': ['12', '173']},{'id': '12', 'type': 'if_statement', 'children': ['13', '17']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'is_Generic'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'subclass'},{'id': '17', 'type': 'block', 'children': ['18', '45', '89', '133', '152', '171']},{'id': '18', 'type': 'if_statement', 'children': ['19', '33']},{'id': '19', 'type': 'boolean_operator', 'children': ['20', '25'], 'value': 'or'},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '24'], 'value': 'is'},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'subclass'},{'id': '23', 'type': 'identifier', 'children': [], 'value': '__origin__'},{'id': '24', 'type': 'None', 'children': []},{'id': '25', 'type': 'not_operator', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '28', 'type': 'argument_list', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'subclass'},{'id': '31', 'type': 'identifier', 'children': [], 'value': '__origin__'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'Mapping'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'return_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': '_issubclass_Generic'},{'id': '37', 'type': 'argument_list', 'children': ['38', '39', '40', '41', '42', '43', '44']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'subclass'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'superclass'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'bound_Generic'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'bound_typevars'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'bound_typevars_readonly'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'follow_fwd_refs'},{'id': '44', 'type': 'identifier', 'children': [], 'value': '_recursion_check'},{'id': '45', 'type': 'if_statement', 'children': ['46', '51', '81']},{'id': '46', 'type': 'comparison_operator', 'children': ['47', '50'], 'value': 'is'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'superclass'},{'id': '49', 'type': 'identifier', 'children': [], 'value': '__args__'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'block', 'children': ['52', '68', '75']},{'id': '52', 'type': 'if_statement', 'children': ['53', '57']},{'id': '53', 'type': 'not_operator', 'children': ['54']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'pytypes'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'check_unbound_types'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'raise_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '+'},{'id': '63', 'type': 'string', 'children': [], 'value': '"Attempted to check unbound mapping type(superclass): "'},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'superclass'},{'id': '68', 'type': 'if_statement', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'pytypes'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'strict_unknown_check'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'False', 'children': []},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'super_args'},{'id': '78', 'type': 'tuple', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'Any'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'Any'},{'id': '81', 'type': 'else_clause', 'children': ['82']},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'super_args'},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'superclass'},{'id': '88', 'type': 'identifier', 'children': [], 'value': '__args__'},{'id': '89', 'type': 'if_statement', 'children': ['90', '95', '125']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '94'], 'value': 'is'},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'subclass'},{'id': '93', 'type': 'identifier', 'children': [], 'value': '__args__'},{'id': '94', 'type': 'None', 'children': []},{'id': '95', 'type': 'block', 'children': ['96', '112', '119']},{'id': '96', 'type': 'if_statement', 'children': ['97', '101']},{'id': '97', 'type': 'not_operator', 'children': ['98']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'pytypes'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'check_unbound_types'},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'raise_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'binary_operator', 'children': ['107', '108'], 'value': '+'},{'id': '107', 'type': 'string', 'children': [], 'value': '"Attempted to check unbound mapping type(subclass): "'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'subclass'},{'id': '112', 'type': 'if_statement', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'pytypes'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'strict_unknown_check'},{'id': '116', 'type': 'block', 'children': ['117']},{'id': '117', 'type': 'return_statement', 'children': ['118']},{'id': '118', 'type': 'False', 'children': []},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'sub_args'},{'id': '122', 'type': 'tuple', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'Any'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'Any'},{'id': '125', 'type': 'else_clause', 'children': ['126']},{'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': 'sub_args'},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'subclass'},{'id': '132', 'type': 'identifier', 'children': [], 'value': '__args__'},{'id': '133', 'type': 'if_statement', 'children': ['134', '149']},{'id': '134', 'type': 'not_operator', 'children': ['135']},{'id': '135', 'type': 'call', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': '_issubclass'},{'id': '137', 'type': 'argument_list', 'children': ['138', '141', '144', '145', '146', '147', '148']},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'sub_args'},{'id': '140', 'type': 'integer', 'children': [], 'value': '0'},{'id': '141', 'type': 'subscript', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'super_args'},{'id': '143', 'type': 'integer', 'children': [], 'value': '0'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'bound_Generic'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'bound_typevars'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'bound_typevars_readonly'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'follow_fwd_refs'},{'id': '148', 'type': 'identifier', 'children': [], 'value': '_recursion_check'},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'return_statement', 'children': ['151']},{'id': '151', 'type': 'False', 'children': []},{'id': '152', 'type': 'if_statement', 'children': ['153', '168']},{'id': '153', 'type': 'not_operator', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': '_issubclass'},{'id': '156', 'type': 'argument_list', 'children': ['157', '160', '163', '164', '165', '166', '167']},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'sub_args'},{'id': '159', 'type': 'integer', 'children': [], 'value': '1'},{'id': '160', 'type': 'subscript', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'super_args'},{'id': '162', 'type': 'integer', 'children': [], 'value': '1'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'bound_Generic'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'bound_typevars'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'bound_typevars_readonly'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'follow_fwd_refs'},{'id': '167', 'type': 'identifier', 'children': [], 'value': '_recursion_check'},{'id': '168', 'type': 'block', 'children': ['169']},{'id': '169', 'type': 'return_statement', 'children': ['170']},{'id': '170', 'type': 'False', 'children': []},{'id': '171', 'type': 'return_statement', 'children': ['172']},{'id': '172', 'type': 'True', 'children': []},{'id': '173', 'type': 'return_statement', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'issubclass'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'subclass'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'superclass'} | def _issubclass_Mapping_covariant(subclass, superclass, bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check):
if is_Generic(subclass):
if subclass.__origin__ is None or not issubclass(subclass.__origin__, Mapping):
return _issubclass_Generic(subclass, superclass, bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check)
if superclass.__args__ is None:
if not pytypes.check_unbound_types:
raise TypeError("Attempted to check unbound mapping type(superclass): "+
str(superclass))
if pytypes.strict_unknown_check:
return False
super_args = (Any, Any)
else:
super_args = superclass.__args__
if subclass.__args__ is None:
if not pytypes.check_unbound_types:
raise TypeError("Attempted to check unbound mapping type(subclass): "+
str(subclass))
if pytypes.strict_unknown_check:
return False
sub_args = (Any, Any)
else:
sub_args = subclass.__args__
if not _issubclass(sub_args[0], super_args[0],
bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check):
return False
if not _issubclass(sub_args[1], super_args[1],
bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check):
return False
return True
return issubclass(subclass, superclass) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_isinstance'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'bound_Generic'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'bound_typevars'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'bound_typevars_readonly'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'follow_fwd_refs'},{'id': '17', 'type': 'True', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': '_recursion_check'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '31', '88', '105']},{'id': '22', 'type': 'if_statement', 'children': ['23', '26']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'bound_typevars'},{'id': '25', 'type': 'None', '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': 'bound_typevars'},{'id': '30', 'type': 'dictionary', 'children': []},{'id': '31', 'type': 'if_statement', 'children': ['32', '44']},{'id': '32', 'type': 'boolean_operator', 'children': ['33', '37'], 'value': 'and'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'is_Generic'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': 'is'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '__origin__'},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'typing'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'Iterable'},{'id': '44', 'type': 'block', 'children': ['45', '54', '61']},{'id': '45', 'type': 'if_statement', 'children': ['46', '51']},{'id': '46', 'type': 'not_operator', 'children': ['47']},{'id': '47', 'type': 'call', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'is_iterable'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'False', 'children': []},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'itp'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'get_iterable_itemtype'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '61', 'type': 'if_statement', 'children': ['62', '65', '71']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'itp'},{'id': '64', 'type': 'None', 'children': []},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'return_statement', 'children': ['67']},{'id': '67', 'type': 'not_operator', 'children': ['68']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'pytypes'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'check_iterables'},{'id': '71', 'type': 'else_clause', 'children': ['72']},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': '_issubclass'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78', '83', '84', '85', '86', '87']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'itp'},{'id': '78', 'type': 'subscript', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '81', 'type': 'identifier', 'children': [], 'value': '__args__'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'bound_Generic'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'bound_typevars'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'bound_typevars_readonly'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'follow_fwd_refs'},{'id': '87', 'type': 'identifier', 'children': [], 'value': '_recursion_check'},{'id': '88', 'type': 'if_statement', 'children': ['89', '93']},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'is_Callable'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'return_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': '_isinstance_Callable'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99', '100', '101', '102', '103', '104']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'bound_Generic'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'bound_typevars'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'bound_typevars_readonly'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'follow_fwd_refs'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_recursion_check'},{'id': '105', 'type': 'return_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': '_issubclass'},{'id': '108', 'type': 'argument_list', 'children': ['109', '113', '114', '115', '116', '117', '118']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'deep_type'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'bound_Generic'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'bound_typevars'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'bound_typevars_readonly'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'follow_fwd_refs'},{'id': '118', 'type': 'identifier', 'children': [], 'value': '_recursion_check'} | def _isinstance(obj, cls, bound_Generic=None, bound_typevars=None,
bound_typevars_readonly=False, follow_fwd_refs=True, _recursion_check=None):
if bound_typevars is None:
bound_typevars = {}
if is_Generic(cls) and cls.__origin__ is typing.Iterable:
if not is_iterable(obj):
return False
itp = get_iterable_itemtype(obj)
if itp is None:
return not pytypes.check_iterables
else:
return _issubclass(itp, cls.__args__[0], bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check)
if is_Callable(cls):
return _isinstance_Callable(obj, cls, bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check)
return _issubclass(deep_type(obj), cls, bound_Generic, bound_typevars,
bound_typevars_readonly, follow_fwd_refs, _recursion_check) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'typelogged_module'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '5', 'type': 'block', 'children': ['6', '14', '67', '73', '99', '105', '128', '138', '193', '218']},{'id': '6', 'type': 'if_statement', 'children': ['7', '11']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'pytypes'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'typelogging_enabled'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '14', 'type': 'if_statement', 'children': ['15', '20']},{'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': 'md'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'if_statement', 'children': ['22', '27', '43']},{'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'in'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '27', 'type': 'block', 'children': ['28', '36']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '31', 'type': 'subscript', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'modules'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '36', 'type': 'if_statement', 'children': ['37', '40']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'return_statement', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '43', 'type': 'elif_clause', 'children': ['44', '51']},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'in'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '46', 'type': 'attribute', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'pytypes'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'typechecker'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_pending_modules'},{'id': '51', 'type': 'block', 'children': ['52', '65']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '63']},{'id': '54', 'type': 'attribute', 'children': ['55', '62']},{'id': '55', 'type': 'subscript', 'children': ['56', '61']},{'id': '56', 'type': 'attribute', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'pytypes'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'typechecker'},{'id': '60', 'type': 'identifier', 'children': [], 'value': '_pending_modules'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'typelogged_module'},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '67', 'type': 'assert_statement', 'children': ['68']},{'id': '68', 'type': '()', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'ismodule'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '73', 'type': 'if_statement', 'children': ['74', '83']},{'id': '74', 'type': 'comparison_operator', 'children': ['75', '78'], 'value': 'in'},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '77', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '78', 'type': 'attribute', 'children': ['79', '82']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'pytypes'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'typechecker'},{'id': '82', 'type': 'identifier', 'children': [], 'value': '_pending_modules'},{'id': '83', 'type': 'block', 'children': ['84']},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '97']},{'id': '86', 'type': 'attribute', 'children': ['87', '96']},{'id': '87', 'type': 'subscript', 'children': ['88', '93']},{'id': '88', 'type': 'attribute', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'pytypes'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'typechecker'},{'id': '92', 'type': 'identifier', 'children': [], 'value': '_pending_modules'},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'typelogged_module'},{'id': '99', 'type': 'assert_statement', 'children': ['100']},{'id': '100', 'type': '()', 'children': ['101']},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'ismodule'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '105', 'type': 'if_statement', 'children': ['106', '125']},{'id': '106', 'type': 'boolean_operator', 'children': ['107', '112', '113'], 'value': 'and'},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '111'], 'value': 'in'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '110', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '111', 'type': 'identifier', 'children': [], 'value': '_fully_typelogged_modules'},{'id': '112', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '119'], 'value': '=='},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': '_fully_typelogged_modules'},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '118', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '124', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '131', 'type': 'list_comprehension', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '133', 'type': 'for_in_clause', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '137', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '138', 'type': 'for_statement', 'children': ['139', '140', '141']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'keys'},{'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': 'memb'},{'id': '145', 'type': 'subscript', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '148', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '150', 'type': 'if_statement', 'children': ['151', '163', '174']},{'id': '151', 'type': 'boolean_operator', 'children': ['152', '156'], 'value': 'and'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': '_check_as_func'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'memb'},{'id': '156', 'type': 'comparison_operator', 'children': ['157', '160'], 'value': '=='},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'memb'},{'id': '159', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '162', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'setattr'},{'id': '167', 'type': 'argument_list', 'children': ['168', '169', '170']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'typelogged_func'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'memb'},{'id': '174', 'type': 'elif_clause', 'children': ['175', '187']},{'id': '175', 'type': 'boolean_operator', 'children': ['176', '180'], 'value': 'and'},{'id': '176', 'type': 'call', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'isclass'},{'id': '178', 'type': 'argument_list', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'memb'},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '184'], 'value': '=='},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'memb'},{'id': '183', 'type': 'identifier', 'children': [], 'value': '__module__'},{'id': '184', 'type': 'attribute', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '186', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '187', 'type': 'block', 'children': ['188']},{'id': '188', 'type': 'expression_statement', 'children': ['189']},{'id': '189', 'type': 'call', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'typelogged_class'},{'id': '191', 'type': 'argument_list', 'children': ['192']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'memb'},{'id': '193', 'type': 'if_statement', 'children': ['194', '204']},{'id': '194', 'type': 'not_operator', 'children': ['195']},{'id': '195', 'type': 'comparison_operator', 'children': ['196', '199'], 'value': 'in'},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '198', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '199', 'type': 'attribute', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'pytypes'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'typechecker'},{'id': '203', 'type': 'identifier', 'children': [], 'value': '_pending_modules'},{'id': '204', 'type': 'block', 'children': ['205']},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'assignment', 'children': ['207', '212']},{'id': '207', 'type': 'subscript', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': '_fully_typelogged_modules'},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '211', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '212', 'type': 'call', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'md'},{'id': '217', 'type': 'identifier', 'children': [], 'value': '__dict__'},{'id': '218', 'type': 'return_statement', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'md'} | def typelogged_module(md):
if not pytypes.typelogging_enabled:
return md
if isinstance(md, str):
if md in sys.modules:
md = sys.modules[md]
if md is None:
return md
elif md in pytypes.typechecker._pending_modules:
pytypes.typechecker._pending_modules[md].append(typelogged_module)
return md
assert(ismodule(md))
if md.__name__ in pytypes.typechecker._pending_modules:
pytypes.typechecker._pending_modules[md.__name__].append(typelogged_module)
assert(ismodule(md))
if md.__name__ in _fully_typelogged_modules and \
_fully_typelogged_modules[md.__name__] == len(md.__dict__):
return md
keys = [key for key in md.__dict__]
for key in keys:
memb = md.__dict__[key]
if _check_as_func(memb) and memb.__module__ == md.__name__:
setattr(md, key, typelogged_func(memb))
elif isclass(memb) and memb.__module__ == md.__name__:
typelogged_class(memb)
if not md.__name__ in pytypes.typechecker._pending_modules:
_fully_typelogged_modules[md.__name__] = len(md.__dict__)
return md |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'import_process_elements'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'diagram_graph'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sequence_flows'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'process_elements_dict'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'plane_element'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '23']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'process_element'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'document'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'getElementsByTagNameNS'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'string', 'children': [], 'value': '"*"'},{'id': '18', 'type': 'attribute', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'process'},{'id': '23', 'type': 'block', 'children': ['24', '32', '45', '51', '65', '92', '137']},{'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': 'BpmnDiagramGraphImport'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'import_process_element'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'process_elements_dict'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'process_element'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'process_id'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'process_element'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'getAttribute'},{'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': 'consts'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'process_attributes'},{'id': '48', 'type': 'subscript', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'process_elements_dict'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'process_id'},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'lane_set_list'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'process_element'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'getElementsByTagNameNS'},{'id': '58', 'type': 'argument_list', 'children': ['59', '60']},{'id': '59', 'type': 'string', 'children': [], 'value': '"*"'},{'id': '60', 'type': 'attribute', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'lane_set'},{'id': '65', 'type': 'if_statement', 'children': ['66', '76']},{'id': '66', 'type': 'boolean_operator', 'children': ['67', '70'], 'value': 'and'},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'is'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'lane_set_list'},{'id': '69', 'type': 'None', 'children': []},{'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': 'lane_set_list'},{'id': '75', 'type': 'integer', 'children': [], 'value': '0'},{'id': '76', 'type': 'block', 'children': ['77', '83']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'lane_set'},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'lane_set_list'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'BpmnDiagramGraphImport'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'import_lane_set_element'},{'id': '88', 'type': 'argument_list', 'children': ['89', '90', '91']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'process_attributes'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'lane_set'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'plane_element'},{'id': '92', 'type': 'for_statement', 'children': ['93', '94', '102']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '94', 'type': 'call', 'children': ['95', '100']},{'id': '95', 'type': 'attribute', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'BpmnImportUtils'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'iterate_elements'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'process_element'},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'if_statement', 'children': ['104', '111']},{'id': '104', 'type': 'comparison_operator', 'children': ['105', '108'], 'value': '!='},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'TEXT_NODE'},{'id': '111', 'type': 'block', 'children': ['112', '125']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'tag_name'},{'id': '115', 'type': 'call', 'children': ['116', '121']},{'id': '116', 'type': 'attribute', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'BpmnImportUtils'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'remove_namespace_from_tag_name'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'tagName'},{'id': '125', 'type': 'expression_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'BpmnDiagramGraphImport'},{'id': '129', 'type': 'identifier', 'children': [], 'value': '__import_element_by_tag_name'},{'id': '130', 'type': 'argument_list', 'children': ['131', '132', '133', '134', '135', '136']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'diagram_graph'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'sequence_flows'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'process_id'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'process_attributes'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'tag_name'},{'id': '137', 'type': 'for_statement', 'children': ['138', '139', '147']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'flow'},{'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': 'utils'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'BpmnImportUtils'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'iterate_elements'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'process_element'},{'id': '147', 'type': 'block', 'children': ['148']},{'id': '148', 'type': 'if_statement', 'children': ['149', '156']},{'id': '149', 'type': 'comparison_operator', 'children': ['150', '153'], 'value': '!='},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'flow'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'nodeType'},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'flow'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'TEXT_NODE'},{'id': '156', 'type': 'block', 'children': ['157', '170']},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'tag_name'},{'id': '160', 'type': 'call', 'children': ['161', '166']},{'id': '161', 'type': 'attribute', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'BpmnImportUtils'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'remove_namespace_from_tag_name'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'flow'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'tagName'},{'id': '170', 'type': 'if_statement', 'children': ['171', '178']},{'id': '171', 'type': 'comparison_operator', 'children': ['172', '173'], 'value': '=='},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'tag_name'},{'id': '173', 'type': 'attribute', 'children': ['174', '177']},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'sequence_flow'},{'id': '178', 'type': 'block', 'children': ['179']},{'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': 'BpmnDiagramGraphImport'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'import_sequence_flow_to_graph'},{'id': '184', 'type': 'argument_list', 'children': ['185', '186', '187', '188']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'diagram_graph'},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'sequence_flows'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'process_id'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'flow'} | def import_process_elements(document, diagram_graph, sequence_flows, process_elements_dict, plane_element):
for process_element in document.getElementsByTagNameNS("*", consts.Consts.process):
BpmnDiagramGraphImport.import_process_element(process_elements_dict, process_element)
process_id = process_element.getAttribute(consts.Consts.id)
process_attributes = process_elements_dict[process_id]
lane_set_list = process_element.getElementsByTagNameNS("*", consts.Consts.lane_set)
if lane_set_list is not None and len(lane_set_list) > 0:
lane_set = lane_set_list[0]
BpmnDiagramGraphImport.import_lane_set_element(process_attributes, lane_set, plane_element)
for element in utils.BpmnImportUtils.iterate_elements(process_element):
if element.nodeType != element.TEXT_NODE:
tag_name = utils.BpmnImportUtils.remove_namespace_from_tag_name(element.tagName)
BpmnDiagramGraphImport.__import_element_by_tag_name(diagram_graph, sequence_flows, process_id,
process_attributes, element, tag_name)
for flow in utils.BpmnImportUtils.iterate_elements(process_element):
if flow.nodeType != flow.TEXT_NODE:
tag_name = utils.BpmnImportUtils.remove_namespace_from_tag_name(flow.tagName)
if tag_name == consts.Consts.sequence_flow:
BpmnDiagramGraphImport.import_sequence_flow_to_graph(diagram_graph, sequence_flows, process_id,
flow) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_nodes_clasification'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'bpmn_diagram'},{'id': '5', 'type': 'block', 'children': ['6', '10', '14', '18', '22', '35', '53', '66', '84', '97', '115', '128', '146', '159', '177', '190', '208', '221', '239', '252', '271', '284', '302', '315', '334', '347', '365']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'nodes_classification'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'classification_element'},{'id': '13', 'type': 'string', 'children': [], 'value': '"Element"'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'classification_start_event'},{'id': '17', 'type': 'string', 'children': [], 'value': '"Start Event"'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'classification_end_event'},{'id': '21', 'type': 'string', 'children': [], 'value': '"End Event"'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'task_list'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'bpmn_diagram'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_nodes'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'attribute', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'task'},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'task_list'},{'id': '38', 'type': 'block', 'children': ['39', '44']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '42', 'type': 'list', 'children': ['43'], 'value': '[classification_element]'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'classification_element'},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'BpmnImportUtils'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'split_join_classification'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'nodes_classification'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'subprocess_list'},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'bpmn_diagram'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_nodes'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'attribute', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'subprocess'},{'id': '66', 'type': 'for_statement', 'children': ['67', '68', '69']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'subprocess_list'},{'id': '69', 'type': 'block', 'children': ['70', '75']},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '73', 'type': 'list', 'children': ['74'], 'value': '[classification_element]'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'classification_element'},{'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': 'BpmnImportUtils'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'split_join_classification'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82', '83']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'nodes_classification'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'complex_gateway_list'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'bpmn_diagram'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'get_nodes'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'attribute', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'complex_gateway'},{'id': '97', 'type': 'for_statement', 'children': ['98', '99', '100']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'complex_gateway_list'},{'id': '100', 'type': 'block', 'children': ['101', '106']},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '104', 'type': 'list', 'children': ['105'], 'value': '[classification_element]'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'classification_element'},{'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': 'BpmnImportUtils'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'split_join_classification'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113', '114']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'nodes_classification'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'event_based_gateway_list'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'bpmn_diagram'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'get_nodes'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'attribute', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'event_based_gateway'},{'id': '128', 'type': 'for_statement', 'children': ['129', '130', '131']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'event_based_gateway_list'},{'id': '131', 'type': 'block', 'children': ['132', '137']},{'id': '132', 'type': 'expression_statement', 'children': ['133']},{'id': '133', 'type': 'assignment', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '135', 'type': 'list', 'children': ['136'], 'value': '[classification_element]'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'classification_element'},{'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': 'BpmnImportUtils'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'split_join_classification'},{'id': '142', 'type': 'argument_list', 'children': ['143', '144', '145']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'nodes_classification'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'inclusive_gateway_list'},{'id': '149', 'type': 'call', 'children': ['150', '153']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'bpmn_diagram'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'get_nodes'},{'id': '153', 'type': 'argument_list', 'children': ['154']},{'id': '154', 'type': 'attribute', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'inclusive_gateway'},{'id': '159', 'type': 'for_statement', 'children': ['160', '161', '162']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'inclusive_gateway_list'},{'id': '162', 'type': 'block', 'children': ['163', '168']},{'id': '163', 'type': 'expression_statement', 'children': ['164']},{'id': '164', 'type': 'assignment', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '166', 'type': 'list', 'children': ['167'], 'value': '[classification_element]'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'classification_element'},{'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': 'BpmnImportUtils'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'split_join_classification'},{'id': '173', 'type': 'argument_list', 'children': ['174', '175', '176']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'nodes_classification'},{'id': '177', 'type': 'expression_statement', 'children': ['178']},{'id': '178', 'type': 'assignment', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'exclusive_gateway_list'},{'id': '180', 'type': 'call', 'children': ['181', '184']},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'bpmn_diagram'},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'get_nodes'},{'id': '184', 'type': 'argument_list', 'children': ['185']},{'id': '185', 'type': 'attribute', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'exclusive_gateway'},{'id': '190', 'type': 'for_statement', 'children': ['191', '192', '193']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'exclusive_gateway_list'},{'id': '193', 'type': 'block', 'children': ['194', '199']},{'id': '194', 'type': 'expression_statement', 'children': ['195']},{'id': '195', 'type': 'assignment', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '197', 'type': 'list', 'children': ['198'], 'value': '[classification_element]'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'classification_element'},{'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': 'BpmnImportUtils'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'split_join_classification'},{'id': '204', 'type': 'argument_list', 'children': ['205', '206', '207']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'nodes_classification'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'parallel_gateway_list'},{'id': '211', 'type': 'call', 'children': ['212', '215']},{'id': '212', 'type': 'attribute', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'bpmn_diagram'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'get_nodes'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'attribute', 'children': ['217', '220']},{'id': '217', 'type': 'attribute', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'parallel_gateway'},{'id': '221', 'type': 'for_statement', 'children': ['222', '223', '224']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'parallel_gateway_list'},{'id': '224', 'type': 'block', 'children': ['225', '230']},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '228', 'type': 'list', 'children': ['229'], 'value': '[classification_element]'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'classification_element'},{'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': 'BpmnImportUtils'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'split_join_classification'},{'id': '235', 'type': 'argument_list', 'children': ['236', '237', '238']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'nodes_classification'},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'start_event_list'},{'id': '242', 'type': 'call', 'children': ['243', '246']},{'id': '243', 'type': 'attribute', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'bpmn_diagram'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'get_nodes'},{'id': '246', 'type': 'argument_list', 'children': ['247']},{'id': '247', 'type': 'attribute', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'start_event'},{'id': '252', 'type': 'for_statement', 'children': ['253', '254', '255']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'start_event_list'},{'id': '255', 'type': 'block', 'children': ['256', '262']},{'id': '256', 'type': 'expression_statement', 'children': ['257']},{'id': '257', 'type': 'assignment', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '259', 'type': 'list', 'children': ['260', '261'], 'value': '[classification_element, classification_start_event]'},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'classification_element'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'classification_start_event'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'BpmnImportUtils'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'split_join_classification'},{'id': '267', 'type': 'argument_list', 'children': ['268', '269', '270']},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'nodes_classification'},{'id': '271', 'type': 'expression_statement', 'children': ['272']},{'id': '272', 'type': 'assignment', 'children': ['273', '274']},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'intermediate_catch_event_list'},{'id': '274', 'type': 'call', 'children': ['275', '278']},{'id': '275', 'type': 'attribute', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'bpmn_diagram'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'get_nodes'},{'id': '278', 'type': 'argument_list', 'children': ['279']},{'id': '279', 'type': 'attribute', 'children': ['280', '283']},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '283', 'type': 'identifier', 'children': [], 'value': 'intermediate_catch_event'},{'id': '284', 'type': 'for_statement', 'children': ['285', '286', '287']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'intermediate_catch_event_list'},{'id': '287', 'type': 'block', 'children': ['288', '293']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '291', 'type': 'list', 'children': ['292'], 'value': '[classification_element]'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'classification_element'},{'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': 'BpmnImportUtils'},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'split_join_classification'},{'id': '298', 'type': 'argument_list', 'children': ['299', '300', '301']},{'id': '299', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'nodes_classification'},{'id': '302', 'type': 'expression_statement', 'children': ['303']},{'id': '303', 'type': 'assignment', 'children': ['304', '305']},{'id': '304', 'type': 'identifier', 'children': [], 'value': 'end_event_list'},{'id': '305', 'type': 'call', 'children': ['306', '309']},{'id': '306', 'type': 'attribute', 'children': ['307', '308']},{'id': '307', 'type': 'identifier', 'children': [], 'value': 'bpmn_diagram'},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'get_nodes'},{'id': '309', 'type': 'argument_list', 'children': ['310']},{'id': '310', 'type': 'attribute', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'end_event'},{'id': '315', 'type': 'for_statement', 'children': ['316', '317', '318']},{'id': '316', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'end_event_list'},{'id': '318', 'type': 'block', 'children': ['319', '325']},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'assignment', 'children': ['321', '322']},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '322', 'type': 'list', 'children': ['323', '324'], 'value': '[classification_element, classification_end_event]'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'classification_element'},{'id': '324', 'type': 'identifier', 'children': [], 'value': 'classification_end_event'},{'id': '325', 'type': 'expression_statement', 'children': ['326']},{'id': '326', 'type': 'call', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'BpmnImportUtils'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'split_join_classification'},{'id': '330', 'type': 'argument_list', 'children': ['331', '332', '333']},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'nodes_classification'},{'id': '334', 'type': 'expression_statement', 'children': ['335']},{'id': '335', 'type': 'assignment', 'children': ['336', '337']},{'id': '336', 'type': 'identifier', 'children': [], 'value': 'intermediate_throw_event_list'},{'id': '337', 'type': 'call', 'children': ['338', '341']},{'id': '338', 'type': 'attribute', 'children': ['339', '340']},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'bpmn_diagram'},{'id': '340', 'type': 'identifier', 'children': [], 'value': 'get_nodes'},{'id': '341', 'type': 'argument_list', 'children': ['342']},{'id': '342', 'type': 'attribute', 'children': ['343', '346']},{'id': '343', 'type': 'attribute', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'consts'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'Consts'},{'id': '346', 'type': 'identifier', 'children': [], 'value': 'intermediate_throw_event'},{'id': '347', 'type': 'for_statement', 'children': ['348', '349', '350']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '349', 'type': 'identifier', 'children': [], 'value': 'intermediate_throw_event_list'},{'id': '350', 'type': 'block', 'children': ['351', '356']},{'id': '351', 'type': 'expression_statement', 'children': ['352']},{'id': '352', 'type': 'assignment', 'children': ['353', '354']},{'id': '353', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '354', 'type': 'list', 'children': ['355'], 'value': '[classification_element]'},{'id': '355', 'type': 'identifier', 'children': [], 'value': 'classification_element'},{'id': '356', 'type': 'expression_statement', 'children': ['357']},{'id': '357', 'type': 'call', 'children': ['358', '361']},{'id': '358', 'type': 'attribute', 'children': ['359', '360']},{'id': '359', 'type': 'identifier', 'children': [], 'value': 'BpmnImportUtils'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'split_join_classification'},{'id': '361', 'type': 'argument_list', 'children': ['362', '363', '364']},{'id': '362', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '363', 'type': 'identifier', 'children': [], 'value': 'classification_labels'},{'id': '364', 'type': 'identifier', 'children': [], 'value': 'nodes_classification'},{'id': '365', 'type': 'return_statement', 'children': ['366']},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'nodes_classification'} | def generate_nodes_clasification(bpmn_diagram):
nodes_classification = {}
classification_element = "Element"
classification_start_event = "Start Event"
classification_end_event = "End Event"
task_list = bpmn_diagram.get_nodes(consts.Consts.task)
for element in task_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
subprocess_list = bpmn_diagram.get_nodes(consts.Consts.subprocess)
for element in subprocess_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
complex_gateway_list = bpmn_diagram.get_nodes(consts.Consts.complex_gateway)
for element in complex_gateway_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
event_based_gateway_list = bpmn_diagram.get_nodes(consts.Consts.event_based_gateway)
for element in event_based_gateway_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
inclusive_gateway_list = bpmn_diagram.get_nodes(consts.Consts.inclusive_gateway)
for element in inclusive_gateway_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
exclusive_gateway_list = bpmn_diagram.get_nodes(consts.Consts.exclusive_gateway)
for element in exclusive_gateway_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
parallel_gateway_list = bpmn_diagram.get_nodes(consts.Consts.parallel_gateway)
for element in parallel_gateway_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
start_event_list = bpmn_diagram.get_nodes(consts.Consts.start_event)
for element in start_event_list:
classification_labels = [classification_element, classification_start_event]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
intermediate_catch_event_list = bpmn_diagram.get_nodes(consts.Consts.intermediate_catch_event)
for element in intermediate_catch_event_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
end_event_list = bpmn_diagram.get_nodes(consts.Consts.end_event)
for element in end_event_list:
classification_labels = [classification_element, classification_end_event]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
intermediate_throw_event_list = bpmn_diagram.get_nodes(consts.Consts.intermediate_throw_event)
for element in intermediate_throw_event_list:
classification_labels = [classification_element]
BpmnImportUtils.split_join_classification(element, classification_labels, nodes_classification)
return nodes_classification |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'hclust_linearize'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '5', 'type': 'block', 'children': ['6', '12', '21']},{'id': '6', 'type': 'import_from_statement', 'children': ['7', '10']},{'id': '7', 'type': 'dotted_name', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'scipy'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'cluster'},{'id': '10', 'type': 'dotted_name', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'hierarchy'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'Z'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'hierarchy'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ward'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'hierarchy'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'leaves_list'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'hierarchy'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'optimal_leaf_ordering'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'Z'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'U'} | def hclust_linearize(U):
from scipy.cluster import hierarchy
Z = hierarchy.ward(U)
return hierarchy.leaves_list(hierarchy.optimal_leaf_ordering(Z, U)) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'kruskal_align'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'V'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'permute_U'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'permute_V'},{'id': '11', 'type': 'False', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '35', '57', '79', '98', '113', '123', '137', '157', '177', '222', '232', '242', '252', '262', '278', '292', '332']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'unrm'},{'id': '16', 'type': 'list_comprehension', 'children': ['17', '30']},{'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '/'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'f'},{'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': 'np'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'norm'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'factors'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'vnrm'},{'id': '38', 'type': 'list_comprehension', 'children': ['39', '52']},{'id': '39', 'type': 'binary_operator', 'children': ['40', '41'], 'value': '/'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '41', 'type': 'call', 'children': ['42', '47']},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'linalg'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'norm'},{'id': '47', 'type': 'argument_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'for_in_clause', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'V'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'factors'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sim_matrices'},{'id': '60', 'type': 'list_comprehension', 'children': ['61', '70']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'dot'},{'id': '65', 'type': 'argument_list', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'T'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '70', 'type': 'for_in_clause', 'children': ['71', '74']},{'id': '71', 'type': 'pattern_list', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '76', 'type': 'argument_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'unrm'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'vnrm'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'cost'},{'id': '82', 'type': 'binary_operator', 'children': ['83', '84'], 'value': '-'},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'call', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '88', 'type': 'argument_list', 'children': ['89', '95']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'sim_matrices'},{'id': '95', 'type': 'keyword_argument', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '97', 'type': 'integer', 'children': [], 'value': '0'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '101', 'type': 'call', 'children': ['102', '107']},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'call', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'Munkres'},{'id': '105', 'type': 'argument_list', 'children': []},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'compute'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'cost'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '112', 'type': 'argument_list', 'children': []},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '118']},{'id': '115', 'type': 'pattern_list', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'prmU'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'prmV'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'list_splat', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'indices'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'similarity'},{'id': '126', 'type': 'call', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '-'},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'subscript', 'children': ['134', '135', '136']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'cost'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'prmU'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'prmV'},{'id': '137', 'type': 'expression_statement', 'children': ['138']},{'id': '138', 'type': 'assignment', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'unmatched_U'},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'binary_operator', 'children': ['144', '153'], 'value': '-'},{'id': '144', 'type': 'call', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'attribute', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'rank'},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'prmU'},{'id': '157', 'type': 'expression_statement', 'children': ['158']},{'id': '158', 'type': 'assignment', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'unmatched_V'},{'id': '160', 'type': 'call', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'binary_operator', 'children': ['164', '173'], 'value': '-'},{'id': '164', 'type': 'call', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'call', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'V'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'rank'},{'id': '173', 'type': 'call', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'prmV'},{'id': '177', 'type': 'if_statement', 'children': ['178', '181', '194', '206', '218']},{'id': '178', 'type': 'boolean_operator', 'children': ['179', '180'], 'value': 'and'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'permute_U'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'permute_V'},{'id': '181', 'type': 'block', 'children': ['182']},{'id': '182', 'type': 'expression_statement', 'children': ['183']},{'id': '183', 'type': 'assignment', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'subscript', 'children': ['191', '192', '193']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'cost'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'prmU'},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'prmV'},{'id': '194', 'type': 'elif_clause', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'permute_V'},{'id': '196', 'type': 'block', 'children': ['197']},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '200', 'type': 'call', 'children': ['201', '204']},{'id': '201', 'type': 'attribute', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '204', 'type': 'argument_list', 'children': ['205']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'prmU'},{'id': '206', 'type': 'elif_clause', 'children': ['207', '208']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'permute_U'},{'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': 'idx'},{'id': '212', 'type': 'call', 'children': ['213', '216']},{'id': '213', 'type': 'attribute', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '216', 'type': 'argument_list', 'children': ['217']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'prmV'},{'id': '218', 'type': 'else_clause', 'children': ['219']},{'id': '219', 'type': 'block', 'children': ['220']},{'id': '220', 'type': 'return_statement', 'children': ['221']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'similarity'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'prmU'},{'id': '225', 'type': 'list_comprehension', 'children': ['226', '229']},{'id': '226', 'type': 'subscript', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'prmU'},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '229', 'type': 'for_in_clause', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'prmV'},{'id': '235', 'type': 'list_comprehension', 'children': ['236', '239']},{'id': '236', 'type': 'subscript', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'prmV'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '239', 'type': 'for_in_clause', 'children': ['240', '241']},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '242', 'type': 'if_statement', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'permute_U'},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'call', 'children': ['247', '250']},{'id': '247', 'type': 'attribute', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'permute'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'prmU'},{'id': '252', 'type': 'if_statement', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'permute_V'},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'V'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'permute'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'prmV'},{'id': '262', 'type': 'expression_statement', 'children': ['263']},{'id': '263', 'type': 'assignment', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'flips'},{'id': '265', 'type': 'call', 'children': ['266', '269']},{'id': '266', 'type': 'attribute', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'sign'},{'id': '269', 'type': 'argument_list', 'children': ['270']},{'id': '270', 'type': 'list_comprehension', 'children': ['271', '275']},{'id': '271', 'type': 'subscript', 'children': ['272', '273', '274']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '273', 'type': 'identifier', 'children': [], 'value': 'prmU'},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'prmV'},{'id': '275', 'type': 'for_in_clause', 'children': ['276', '277']},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'F'},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'sim_matrices'},{'id': '278', 'type': 'expression_statement', 'children': ['279']},{'id': '279', 'type': 'augmented_assignment', 'children': ['280', '283'], 'value': '*='},{'id': '280', 'type': 'subscript', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'flips'},{'id': '282', 'type': 'integer', 'children': [], 'value': '0'},{'id': '283', 'type': 'call', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'prod'},{'id': '287', 'type': 'argument_list', 'children': ['288', '289']},{'id': '288', 'type': 'identifier', 'children': [], 'value': 'flips'},{'id': '289', 'type': 'keyword_argument', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '291', 'type': 'integer', 'children': [], 'value': '0'},{'id': '292', 'type': 'if_statement', 'children': ['293', '294', '312']},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'permute_U'},{'id': '294', 'type': 'block', 'children': ['295']},{'id': '295', 'type': 'for_statement', 'children': ['296', '299', '303']},{'id': '296', 'type': 'pattern_list', 'children': ['297', '298']},{'id': '297', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '298', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '299', 'type': 'call', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '301', 'type': 'argument_list', 'children': ['302']},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'flips'},{'id': '303', 'type': 'block', 'children': ['304']},{'id': '304', 'type': 'expression_statement', 'children': ['305']},{'id': '305', 'type': 'augmented_assignment', 'children': ['306', '311'], 'value': '*='},{'id': '306', 'type': 'subscript', 'children': ['307', '310']},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'factors'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '312', 'type': 'elif_clause', 'children': ['313', '314']},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'permute_V'},{'id': '314', 'type': 'block', 'children': ['315']},{'id': '315', 'type': 'for_statement', 'children': ['316', '319', '323']},{'id': '316', 'type': 'pattern_list', 'children': ['317', '318']},{'id': '317', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '319', 'type': 'call', 'children': ['320', '321']},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '321', 'type': 'argument_list', 'children': ['322']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'flips'},{'id': '323', 'type': 'block', 'children': ['324']},{'id': '324', 'type': 'expression_statement', 'children': ['325']},{'id': '325', 'type': 'augmented_assignment', 'children': ['326', '331'], 'value': '*='},{'id': '326', 'type': 'subscript', 'children': ['327', '330']},{'id': '327', 'type': 'attribute', 'children': ['328', '329']},{'id': '328', 'type': 'identifier', 'children': [], 'value': 'V'},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'factors'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '331', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '332', 'type': 'return_statement', 'children': ['333']},{'id': '333', 'type': 'identifier', 'children': [], 'value': 'similarity'} | def kruskal_align(U, V, permute_U=False, permute_V=False):
unrm = [f / np.linalg.norm(f, axis=0) for f in U.factors]
vnrm = [f / np.linalg.norm(f, axis=0) for f in V.factors]
sim_matrices = [np.dot(u.T, v) for u, v in zip(unrm, vnrm)]
cost = 1 - np.mean(np.abs(sim_matrices), axis=0)
indices = Munkres().compute(cost.copy())
prmU, prmV = zip(*indices)
similarity = np.mean(1 - cost[prmU, prmV])
unmatched_U = list(set(range(U.rank)) - set(prmU))
unmatched_V = list(set(range(V.rank)) - set(prmV))
if permute_U and permute_V:
idx = np.argsort(cost[prmU, prmV])
elif permute_V:
idx = np.argsort(prmU)
elif permute_U:
idx = np.argsort(prmV)
else:
return similarity
prmU = [prmU[i] for i in idx]
prmV = [prmV[i] for i in idx]
if permute_U:
U.permute(prmU)
if permute_V:
V.permute(prmV)
flips = np.sign([F[prmU, prmV] for F in sim_matrices])
flips[0] *= np.prod(flips, axis=0)
if permute_U:
for i, f in enumerate(flips):
U.factors[i] *= f
elif permute_V:
for i, f in enumerate(flips):
V.factors[i] *= f
return similarity |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'randn_ktensor'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'rank'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'norm'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'random_state'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'block', 'children': ['13', '20', '38']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'rns'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_check_random_state'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'random_state'},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'factors'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'KTensor'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'list_comprehension', 'children': ['27', '35']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'rns'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'standard_normal'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'tuple', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'rank'},{'id': '35', 'type': 'for_in_clause', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_rescale_tensor'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'factors'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'norm'} | def randn_ktensor(shape, rank, norm=None, random_state=None):
rns = _check_random_state(random_state)
factors = KTensor([rns.standard_normal((i, rank)) for i in shape])
return _rescale_tensor(factors, norm) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fit'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'replicates'},{'id': '9', 'type': 'integer', 'children': [], 'value': '1'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '12', 'type': 'True', 'children': []},{'id': '13', 'type': 'block', 'children': ['14', '29', '177', '218', '279']},{'id': '14', 'type': 'if_statement', 'children': ['15', '23']},{'id': '15', 'type': 'not_operator', 'children': ['16']},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'Iterable'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '27', 'type': 'tuple', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '29', 'type': 'for_statement', 'children': ['30', '31', '32']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '32', 'type': 'block', 'children': ['33', '48', '78', '107']},{'id': '33', 'type': 'if_statement', 'children': ['34', '39']},{'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'not'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '47']},{'id': '42', 'type': 'subscript', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '47', 'type': 'list', 'children': [], 'value': '[]'},{'id': '48', 'type': 'if_statement', 'children': ['49', '50', '69']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'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': 'itr'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'trange'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58', '66']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'replicates'},{'id': '58', 'type': 'keyword_argument', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'string', 'children': [], 'value': "'Fitting rank-{} models'"},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'leave'},{'id': '68', 'type': 'False', 'children': []},{'id': '69', 'type': 'else_clause', 'children': ['70']},{'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': 'itr'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'replicates'},{'id': '78', 'type': 'for_statement', 'children': ['79', '80', '81']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'itr'},{'id': '81', 'type': 'block', 'children': ['82', '96']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'model_fit'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_fit_method'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91', '92']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'X'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '92', 'type': 'dictionary_splat', 'children': ['93']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '95', 'type': 'identifier', 'children': [], 'value': '_fit_options'},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'call', 'children': ['98', '105']},{'id': '98', 'type': 'attribute', 'children': ['99', '104']},{'id': '99', 'type': 'subscript', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '105', 'type': 'argument_list', 'children': ['106']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'model_fit'},{'id': '107', 'type': 'if_statement', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '109', 'type': 'block', 'children': ['110', '127', '144', '161']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'min_obj'},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'list_comprehension', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '120', 'type': 'for_in_clause', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'res'},{'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': 'results'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'assignment', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'max_obj'},{'id': '130', 'type': 'call', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '132', 'type': 'argument_list', 'children': ['133']},{'id': '133', 'type': 'list_comprehension', 'children': ['134', '137']},{'id': '134', 'type': 'attribute', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '137', 'type': 'for_in_clause', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '139', 'type': 'subscript', 'children': ['140', '143']},{'id': '140', 'type': 'attribute', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'elapsed'},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'list_comprehension', 'children': ['151', '154']},{'id': '151', 'type': 'attribute', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'total_time'},{'id': '154', 'type': 'for_in_clause', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '156', 'type': 'subscript', 'children': ['157', '160']},{'id': '157', 'type': 'attribute', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'call', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '172']},{'id': '166', 'type': 'attribute', 'children': ['167', '171']},{'id': '167', 'type': 'concatenated_string', 'children': ['168', '169', '170']},{'id': '168', 'type': 'string', 'children': [], 'value': "'Rank-{} models: min obj, {:.2f}; '"},{'id': '169', 'type': 'string', 'children': [], 'value': "'max obj, {:.2f}; time to fit, '"},{'id': '170', 'type': 'string', 'children': [], 'value': "'{:.1f}s'"},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '172', 'type': 'argument_list', 'children': ['173', '174', '175', '176']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'min_obj'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'max_obj'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'elapsed'},{'id': '177', 'type': 'for_statement', 'children': ['178', '179', '180']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '180', 'type': 'block', 'children': ['181', '200']},{'id': '181', 'type': 'expression_statement', 'children': ['182']},{'id': '182', 'type': 'assignment', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '184', 'type': 'call', 'children': ['185', '188']},{'id': '185', 'type': 'attribute', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '188', 'type': 'argument_list', 'children': ['189']},{'id': '189', 'type': 'list_comprehension', 'children': ['190', '193']},{'id': '190', 'type': 'attribute', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '193', 'type': 'for_in_clause', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '195', 'type': 'subscript', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '200', 'type': 'expression_statement', 'children': ['201']},{'id': '201', 'type': 'assignment', 'children': ['202', '207']},{'id': '202', 'type': 'subscript', 'children': ['203', '206']},{'id': '203', 'type': 'attribute', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '207', 'type': 'list_comprehension', 'children': ['208', '215']},{'id': '208', 'type': 'subscript', 'children': ['209', '214']},{'id': '209', 'type': 'subscript', 'children': ['210', '213']},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '215', 'type': 'for_in_clause', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '218', 'type': 'for_statement', 'children': ['219', '220', '231']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '220', 'type': 'call', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '222', 'type': 'argument_list', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227']},{'id': '226', 'type': 'integer', 'children': [], 'value': '1'},{'id': '227', 'type': 'call', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '229', 'type': 'argument_list', 'children': ['230']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '231', 'type': 'block', 'children': ['232', '246', '258', '270']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'assignment', 'children': ['234', '237']},{'id': '234', 'type': 'pattern_list', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'r0'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'r1'},{'id': '237', 'type': 'expression_list', 'children': ['238', '243']},{'id': '238', 'type': 'subscript', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '240', 'type': 'binary_operator', 'children': ['241', '242'], 'value': '-'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '242', 'type': 'integer', 'children': [], 'value': '1'},{'id': '243', 'type': 'subscript', 'children': ['244', '245']},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '245', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'assignment', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '249', 'type': 'attribute', 'children': ['250', '257']},{'id': '250', 'type': 'subscript', 'children': ['251', '256']},{'id': '251', 'type': 'subscript', 'children': ['252', '255']},{'id': '252', 'type': 'attribute', 'children': ['253', '254']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'r0'},{'id': '256', 'type': 'integer', 'children': [], 'value': '0'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'factors'},{'id': '258', 'type': 'expression_statement', 'children': ['259']},{'id': '259', 'type': 'assignment', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'V'},{'id': '261', 'type': 'attribute', 'children': ['262', '269']},{'id': '262', 'type': 'subscript', 'children': ['263', '268']},{'id': '263', 'type': 'subscript', 'children': ['264', '267']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'r1'},{'id': '268', 'type': 'integer', 'children': [], 'value': '0'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'factors'},{'id': '270', 'type': 'expression_statement', 'children': ['271']},{'id': '271', 'type': 'call', 'children': ['272', '273']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'kruskal_align'},{'id': '273', 'type': 'argument_list', 'children': ['274', '275', '276']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'V'},{'id': '276', 'type': 'keyword_argument', 'children': ['277', '278']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'permute_U'},{'id': '278', 'type': 'True', 'children': []},{'id': '279', 'type': 'for_statement', 'children': ['280', '281', '282']},{'id': '280', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'ranks'},{'id': '282', 'type': 'block', 'children': ['283', '295', '307']},{'id': '283', 'type': 'expression_statement', 'children': ['284']},{'id': '284', 'type': 'assignment', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '286', 'type': 'attribute', 'children': ['287', '294']},{'id': '287', 'type': 'subscript', 'children': ['288', '293']},{'id': '288', 'type': 'subscript', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '293', 'type': 'integer', 'children': [], 'value': '0'},{'id': '294', 'type': 'identifier', 'children': [], 'value': 'factors'},{'id': '295', 'type': 'expression_statement', 'children': ['296']},{'id': '296', 'type': 'assignment', 'children': ['297', '306']},{'id': '297', 'type': 'attribute', 'children': ['298', '305']},{'id': '298', 'type': 'subscript', 'children': ['299', '304']},{'id': '299', 'type': 'subscript', 'children': ['300', '303']},{'id': '300', 'type': 'attribute', 'children': ['301', '302']},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '302', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '303', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '304', 'type': 'integer', 'children': [], 'value': '0'},{'id': '305', 'type': 'identifier', 'children': [], 'value': 'similarity'},{'id': '306', 'type': 'float', 'children': [], 'value': '1.0'},{'id': '307', 'type': 'for_statement', 'children': ['308', '309', '318']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '309', 'type': 'subscript', 'children': ['310', '315']},{'id': '310', 'type': 'subscript', 'children': ['311', '314']},{'id': '311', 'type': 'attribute', 'children': ['312', '313']},{'id': '312', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '313', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '314', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '315', 'type': 'slice', 'children': ['316', '317']},{'id': '316', 'type': 'integer', 'children': [], 'value': '1'},{'id': '317', 'type': 'colon', 'children': []},{'id': '318', 'type': 'block', 'children': ['319']},{'id': '319', 'type': 'expression_statement', 'children': ['320']},{'id': '320', 'type': 'assignment', 'children': ['321', '324']},{'id': '321', 'type': 'attribute', 'children': ['322', '323']},{'id': '322', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '323', 'type': 'identifier', 'children': [], 'value': 'similarity'},{'id': '324', 'type': 'call', 'children': ['325', '326']},{'id': '325', 'type': 'identifier', 'children': [], 'value': 'kruskal_align'},{'id': '326', 'type': 'argument_list', 'children': ['327', '328', '331']},{'id': '327', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '328', 'type': 'attribute', 'children': ['329', '330']},{'id': '329', 'type': 'identifier', 'children': [], 'value': 'res'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'factors'},{'id': '331', 'type': 'keyword_argument', 'children': ['332', '333']},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'permute_V'},{'id': '333', 'type': 'True', 'children': []} | def fit(self, X, ranks, replicates=1, verbose=True):
if not isinstance(ranks, collections.Iterable):
ranks = (ranks,)
for r in ranks:
if r not in self.results:
self.results[r] = []
if verbose:
itr = trange(replicates,
desc='Fitting rank-{} models'.format(r),
leave=False)
else:
itr = range(replicates)
for i in itr:
model_fit = self._fit_method(X, r, **self._fit_options)
self.results[r].append(model_fit)
if verbose:
min_obj = min([res.obj for res in self.results[r]])
max_obj = max([res.obj for res in self.results[r]])
elapsed = sum([res.total_time for res in self.results[r]])
print('Rank-{} models: min obj, {:.2f}; '
'max obj, {:.2f}; time to fit, '
'{:.1f}s'.format(r, min_obj, max_obj, elapsed))
for r in ranks:
idx = np.argsort([result.obj for result in self.results[r]])
self.results[r] = [self.results[r][i] for i in idx]
for i in reversed(range(1, len(ranks))):
r0, r1 = ranks[i-1], ranks[i]
U = self.results[r0][0].factors
V = self.results[r1][0].factors
kruskal_align(U, V, permute_U=True)
for r in ranks:
U = self.results[r][0].factors
self.results[r][0].similarity = 1.0
for res in self.results[r][1:]:
res.similarity = kruskal_align(U, res.factors, permute_V=True) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_create_model_class'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '6', 'type': 'block', 'children': ['7', '17', '42', '60', '72', '111', '155']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'cls_name'},{'id': '10', 'type': 'call', 'children': ['11', '14']},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '16', 'type': 'string', 'children': [], 'value': "'_'"},{'id': '17', 'type': 'if_statement', 'children': ['18', '25']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '24'], 'value': '<'},{'id': '19', 'type': 'subscript', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'version_info'},{'id': '23', 'type': 'integer', 'children': [], 'value': '0'},{'id': '24', 'type': 'integer', 'children': [], 'value': '3'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '32']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'cls_name'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'unicode'},{'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': 'cls_name'},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cls_name'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '45', 'type': 'dictionary', 'children': ['46', '49', '54', '57']},{'id': '46', 'type': 'pair', 'children': ['47', '48']},{'id': '47', 'type': 'string', 'children': [], 'value': "'_env'"},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '49', 'type': 'pair', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'_odoo'"},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '53', 'type': 'identifier', 'children': [], 'value': '_odoo'},{'id': '54', 'type': 'pair', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'_name'"},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '57', 'type': 'pair', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': "'_columns'"},{'id': '59', 'type': 'dictionary', 'children': []},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'fields_get'},{'id': '63', 'type': 'call', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': '_odoo'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'execute'},{'id': '69', 'type': 'argument_list', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '71', 'type': 'string', 'children': [], 'value': "'fields_get'"},{'id': '72', 'type': 'for_statement', 'children': ['73', '76', '81']},{'id': '73', 'type': 'pattern_list', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'field_data'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'fields_get'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '80', 'type': 'argument_list', 'children': []},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'if_statement', 'children': ['83', '86']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'not'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'FIELDS_RESERVED'},{'id': '86', 'type': 'block', 'children': ['87', '97', '105']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'Field'},{'id': '90', 'type': 'call', 'children': ['91', '94']},{'id': '91', 'type': 'attribute', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'generate_field'},{'id': '94', 'type': 'argument_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'field_data'},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '104']},{'id': '99', 'type': 'subscript', 'children': ['100', '103']},{'id': '100', 'type': 'subscript', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '102', 'type': 'string', 'children': [], 'value': "'_columns'"},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'Field'},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '110']},{'id': '107', 'type': 'subscript', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'Field'},{'id': '111', 'type': 'if_statement', 'children': ['112', '117']},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'not'},{'id': '113', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '116', 'type': 'string', 'children': [], 'value': "'_columns'"},{'id': '117', 'type': 'block', 'children': ['118', '131', '141', '149']},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'field_data'},{'id': '121', 'type': 'dictionary', 'children': ['122', '125', '128']},{'id': '122', 'type': 'pair', 'children': ['123', '124']},{'id': '123', 'type': 'string', 'children': [], 'value': "'type'"},{'id': '124', 'type': 'string', 'children': [], 'value': "'text'"},{'id': '125', 'type': 'pair', 'children': ['126', '127']},{'id': '126', 'type': 'string', 'children': [], 'value': "'string'"},{'id': '127', 'type': 'string', 'children': [], 'value': "'Name'"},{'id': '128', 'type': 'pair', 'children': ['129', '130']},{'id': '129', 'type': 'string', 'children': [], 'value': "'readonly'"},{'id': '130', 'type': 'True', 'children': []},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'Field'},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'fields'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'generate_field'},{'id': '138', 'type': 'argument_list', 'children': ['139', '140']},{'id': '139', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'field_data'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '148']},{'id': '143', 'type': 'subscript', 'children': ['144', '147']},{'id': '144', 'type': 'subscript', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'attrs'},{'id': '146', 'type': 'string', 'children': [], 'value': "'_columns'"},{'id': '147', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'Field'},{'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': 'attrs'},{'id': '153', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'Field'},{'id': '155', 'type': 'return_statement', 'children': ['156']},{'id': '156', 'type': 'call', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '158', 'type': 'argument_list', 'children': ['159', '160', '162']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'cls_name'},{'id': '160', 'type': 'tuple', 'children': ['161']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'Model'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'attrs'} | def _create_model_class(self, model):
cls_name = model.replace('.', '_')
if sys.version_info[0] < 3:
if isinstance(cls_name, unicode):
cls_name = cls_name.encode('utf-8')
attrs = {
'_env': self,
'_odoo': self._odoo,
'_name': model,
'_columns': {},
}
fields_get = self._odoo.execute(model, 'fields_get')
for field_name, field_data in fields_get.items():
if field_name not in FIELDS_RESERVED:
Field = fields.generate_field(field_name, field_data)
attrs['_columns'][field_name] = Field
attrs[field_name] = Field
if 'name' not in attrs['_columns']:
field_data = {'type': 'text', 'string': 'Name', 'readonly': True}
Field = fields.generate_field('name', field_data)
attrs['_columns']['name'] = Field
attrs['name'] = Field
return type(cls_name, (Model,), attrs) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_init_values'},{'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': 'context'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '22', '26', '56']},{'id': '9', 'type': 'if_statement', 'children': ['10', '13']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'context'},{'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': 'context'},{'id': '17', 'type': 'attribute', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'env'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'basic_fields'},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'for_statement', 'children': ['27', '28', '31']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_columns'},{'id': '31', 'type': 'block', 'children': ['32', '40']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'field'},{'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': '_columns'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '40', 'type': 'if_statement', 'children': ['41', '48']},{'id': '41', 'type': 'not_operator', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46', '47']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '46', 'type': 'string', 'children': [], 'value': "'relation'"},{'id': '47', 'type': 'False', 'children': []},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'basic_fields'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '56', 'type': 'if_statement', 'children': ['57', '60', '158']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '60', 'type': 'block', 'children': ['61', '81', '87', '124', '135']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '64', 'type': 'call', 'children': ['65', '70']},{'id': '65', 'type': 'attribute', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '70', 'type': 'argument_list', 'children': ['71', '74', '75', '78']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'basic_fields'},{'id': '75', 'type': 'keyword_argument', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '78', 'type': 'keyword_argument', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'load'},{'id': '80', 'type': 'string', 'children': [], 'value': "'_classic_write'"},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'ids_fetched'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '86', 'type': 'argument_list', 'children': []},{'id': '87', 'type': 'for_statement', 'children': ['88', '89', '90']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'rows'},{'id': '90', 'type': 'block', 'children': ['91', '100']},{'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': 'ids_fetched'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '99', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '100', 'type': 'for_statement', 'children': ['101', '102', '103']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '103', 'type': 'block', 'children': ['104', '110']},{'id': '104', 'type': 'if_statement', 'children': ['105', '108']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': '=='},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '107', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'continue_statement', 'children': []},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '121']},{'id': '112', 'type': 'subscript', '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': '_values'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '120', 'type': 'string', 'children': [], 'value': "'id'"},{'id': '121', 'type': 'subscript', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'row'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'assignment', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'ids_in_error'},{'id': '127', 'type': 'binary_operator', 'children': ['128', '134'], 'value': '-'},{'id': '128', 'type': 'call', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '130', 'type': 'argument_list', 'children': ['131']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'ids_fetched'},{'id': '135', 'type': 'if_statement', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'ids_in_error'},{'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': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'string', 'children': [], 'value': '"There is no \'{model}\' record with IDs {ids}."'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '146', 'type': 'argument_list', 'children': ['147', '152']},{'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '149', 'type': 'attribute', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '151', 'type': 'identifier', 'children': [], 'value': '_name'},{'id': '152', 'type': 'keyword_argument', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'ids_in_error'},{'id': '158', 'type': 'else_clause', 'children': ['159']},{'id': '159', 'type': 'block', 'children': ['160', '179']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'default_get'},{'id': '163', 'type': 'call', 'children': ['164', '169']},{'id': '164', 'type': 'attribute', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '167', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'default_get'},{'id': '169', 'type': 'argument_list', 'children': ['170', '176']},{'id': '170', 'type': 'call', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '172', 'type': 'argument_list', 'children': ['173']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '175', 'type': 'identifier', 'children': [], 'value': '_columns'},{'id': '176', 'type': 'keyword_argument', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'context'},{'id': '179', 'type': 'for_statement', 'children': ['180', '181', '184']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '181', 'type': 'attribute', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '183', 'type': 'identifier', 'children': [], 'value': '_columns'},{'id': '184', 'type': 'block', 'children': ['185']},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'assignment', 'children': ['187', '194']},{'id': '187', 'type': 'subscript', 'children': ['188', '193']},{'id': '188', 'type': 'subscript', 'children': ['189', '192']},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '191', 'type': 'identifier', 'children': [], 'value': '_values'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '193', 'type': 'None', 'children': []},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'default_get'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'field_name'},{'id': '200', 'type': 'False', 'children': []} | def _init_values(self, context=None):
if context is None:
context = self.env.context
basic_fields = []
for field_name in self._columns:
field = self._columns[field_name]
if not getattr(field, 'relation', False):
basic_fields.append(field_name)
if self.ids:
rows = self.__class__.read(
self.ids, basic_fields, context=context, load='_classic_write')
ids_fetched = set()
for row in rows:
ids_fetched.add(row['id'])
for field_name in row:
if field_name == 'id':
continue
self._values[field_name][row['id']] = row[field_name]
ids_in_error = set(self.ids) - ids_fetched
if ids_in_error:
raise ValueError(
"There is no '{model}' record with IDs {ids}.".format(
model=self._name, ids=list(ids_in_error)))
else:
default_get = self.__class__.default_get(
list(self._columns), context=context)
for field_name in self._columns:
self._values[field_name][None] = default_get.get(
field_name, False) |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_resource_id'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '5', 'type': 'block', 'children': ['6', '12', '21', '121']},{'id': '6', 'type': 'if_statement', 'children': ['7', '9']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'return_statement', 'children': ['11']},{'id': '11', 'type': 'dictionary', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_ARMID_RE'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '21', 'type': 'if_statement', 'children': ['22', '23', '110']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '23', 'type': 'block', 'children': ['24', '32', '45', '49', '88', '103']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'groupdict'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': '_CHILDREN_RE'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'finditer'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'boolean_operator', 'children': ['41', '44'], 'value': 'or'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '43', 'type': 'string', 'children': [], 'value': "'children'"},{'id': '44', 'type': 'string', 'children': [], 'value': "''"},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'for_statement', 'children': ['50', '53', '57']},{'id': '50', 'type': 'pattern_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '55', 'type': 'argument_list', 'children': ['56']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '57', 'type': 'block', 'children': ['58']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'update'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'dictionary_comprehension', 'children': ['65', '75']},{'id': '65', 'type': 'pair', 'children': ['66', '74']},{'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '+'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '%'},{'id': '69', 'type': 'string', 'children': [], 'value': "'_%d'"},{'id': '70', 'type': '()', 'children': ['71']},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '+'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '75', 'type': 'for_in_clause', 'children': ['76', '79']},{'id': '76', 'type': 'pattern_list', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '79', 'type': 'call', 'children': ['80', '87']},{'id': '80', 'type': 'attribute', 'children': ['81', '86']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'groupdict'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '87', 'type': 'argument_list', 'children': []},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '93']},{'id': '90', 'type': 'subscript', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '92', 'type': 'string', 'children': [], 'value': "'last_child_num'"},{'id': '93', 'type': 'conditional_expression', 'children': ['94', '97', '102'], 'value': 'if'},{'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '+'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '96', 'type': 'integer', 'children': [], 'value': '1'},{'id': '97', 'type': 'call', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '99', 'type': 'argument_list', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '102', 'type': 'None', 'children': []},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '106', 'type': 'call', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': '_populate_alternate_kwargs'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'result'},{'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': 'result'},{'id': '115', 'type': 'call', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'rid'},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'dictionary_comprehension', 'children': ['123', '126', '135']},{'id': '123', 'type': 'pair', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '126', 'type': 'for_in_clause', 'children': ['127', '130']},{'id': '127', 'type': 'pattern_list', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '134', 'type': 'argument_list', 'children': []},{'id': '135', 'type': 'if_clause', 'children': ['136']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': 'is'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '138', 'type': 'None', 'children': []} | def parse_resource_id(rid):
if not rid:
return {}
match = _ARMID_RE.match(rid)
if match:
result = match.groupdict()
children = _CHILDREN_RE.finditer(result['children'] or '')
count = None
for count, child in enumerate(children):
result.update({
key + '_%d' % (count + 1): group for key, group in child.groupdict().items()})
result['last_child_num'] = count + 1 if isinstance(count, int) else None
result = _populate_alternate_kwargs(result)
else:
result = dict(name=rid)
return {key: value for key, value in result.items() if value is not None} |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'lookup_instance'},{'id': '3', 'type': 'parameters', 'children': ['4', '8', '13', '18']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '8', 'type': 'typed_default_parameter', 'children': ['9', '10', '12']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '10', 'type': 'type', 'children': ['11']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '12', 'type': 'string', 'children': [], 'value': "''"},{'id': '13', 'type': 'typed_default_parameter', 'children': ['14', '15', '17']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'image_name'},{'id': '15', 'type': 'type', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '17', 'type': 'string', 'children': [], 'value': "''"},{'id': '18', 'type': 'typed_default_parameter', 'children': ['19', '20', '22']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '20', 'type': 'type', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '22', 'type': 'tuple', 'children': ['23', '24', '25']},{'id': '23', 'type': 'string', 'children': [], 'value': "'running'"},{'id': '24', 'type': 'string', 'children': [], 'value': "'stopped'"},{'id': '25', 'type': 'string', 'children': [], 'value': "'initializing'"},{'id': '26', 'type': 'block', 'children': ['27', '33', '53', '59', '65', '69']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'ec2'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'get_ec2_resource'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '36', 'type': 'call', 'children': ['37', '42']},{'id': '37', 'type': 'attribute', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ec2'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'Filters'},{'id': '45', 'type': 'list', 'children': ['46'], 'value': "[{'Name': 'instance-state-name', 'Values': states}]"},{'id': '46', 'type': 'dictionary', 'children': ['47', '50']},{'id': '47', 'type': 'pair', 'children': ['48', '49']},{'id': '48', 'type': 'string', 'children': [], 'value': "'Name'"},{'id': '49', 'type': 'string', 'children': [], 'value': "'instance-state-name'"},{'id': '50', 'type': 'pair', 'children': ['51', '52']},{'id': '51', 'type': 'string', 'children': [], 'value': "'Values'"},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'states'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'get_prefix'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'get_username'},{'id': '64', 'type': 'argument_list', 'children': []},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '68', 'type': 'list', 'children': [], 'value': '[]'},{'id': '69', 'type': 'for_statement', 'children': ['70', '71', '76']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'instances'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'block', 'children': ['77', '84', '90', '101', '112', '123', '133', '145', '152', '160']},{'id': '77', 'type': 'expression_statement', 'children': ['78']},{'id': '78', 'type': 'assignment', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'instance_name'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'get_name'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '84', 'type': 'if_statement', 'children': ['85', '88']},{'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': '!='},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'instance_name'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'continue_statement', 'children': []},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '95']},{'id': '92', 'type': 'pattern_list', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'seen_prefix'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'seen_username'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'parse_key_name'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'key_name'},{'id': '101', 'type': 'if_statement', 'children': ['102', '105']},{'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': '!='},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'seen_prefix'},{'id': '105', 'type': 'block', 'children': ['106', '111']},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'call', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'string', 'children': [], 'value': 'f"Found {name} launched under {seen_prefix}, ignoring"'},{'id': '111', 'type': 'continue_statement', 'children': []},{'id': '112', 'type': 'if_statement', 'children': ['113', '116']},{'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': '!='},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'seen_username'},{'id': '116', 'type': 'block', 'children': ['117', '122']},{'id': '117', 'type': 'expression_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'string', 'children': [], 'value': 'f"Found {name} launched by {seen_username}, ignoring"'},{'id': '122', 'type': 'continue_statement', 'children': []},{'id': '123', 'type': 'if_statement', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '125', 'type': 'block', 'children': ['126']},{'id': '126', 'type': 'assert_statement', 'children': ['127', '132']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '131'], 'value': '=='},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'instance_type'},{'id': '132', 'type': 'string', 'children': [], 'value': 'f"Found existing instance for job {name} but different instance type ({i.instance_type}) than requested ({instance_type}), terminate {name} first or use new task name."'},{'id': '133', 'type': 'if_statement', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'image_name'},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'assert_statement', 'children': ['137', '144']},{'id': '137', 'type': 'comparison_operator', 'children': ['138', '143'], 'value': '=='},{'id': '138', 'type': 'attribute', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'image'},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'image_name'},{'id': '144', 'type': 'string', 'children': [], 'value': 'f"Found existing instance for job {name} but launched with different image ({i.image.name}) than requested ({image_name}), terminate {name} first or use new task 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': 'result'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '150', 'type': 'argument_list', 'children': ['151']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '152', 'type': 'assert_statement', 'children': ['153', '159']},{'id': '153', 'type': 'comparison_operator', 'children': ['154', '158'], 'value': '<'},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '158', 'type': 'integer', 'children': [], 'value': '2'},{'id': '159', 'type': 'string', 'children': [], 'value': 'f"Found two instances with name {name}"'},{'id': '160', 'type': 'if_statement', 'children': ['161', '163', '166']},{'id': '161', 'type': 'not_operator', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'return_statement', 'children': ['165']},{'id': '165', 'type': 'None', 'children': []},{'id': '166', 'type': 'else_clause', 'children': ['167']},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'return_statement', 'children': ['169']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '171', 'type': 'integer', 'children': [], 'value': '0'} | def lookup_instance(name: str, instance_type: str = '', image_name: str = '',
states: tuple = ('running', 'stopped', 'initializing')):
ec2 = get_ec2_resource()
instances = ec2.instances.filter(
Filters=[{'Name': 'instance-state-name', 'Values': states}])
prefix = get_prefix()
username = get_username()
result = []
for i in instances.all():
instance_name = get_name(i)
if instance_name != name:
continue
seen_prefix, seen_username = parse_key_name(i.key_name)
if prefix != seen_prefix:
print(f"Found {name} launched under {seen_prefix}, ignoring")
continue
if username != seen_username:
print(f"Found {name} launched by {seen_username}, ignoring")
continue
if instance_type:
assert i.instance_type == instance_type, f"Found existing instance for job {name} but different instance type ({i.instance_type}) than requested ({instance_type}), terminate {name} first or use new task name."
if image_name:
assert i.image.name == image_name, f"Found existing instance for job {name} but launched with different image ({i.image.name}) than requested ({image_name}), terminate {name} first or use new task name."
result.append(i)
assert len(result) < 2, f"Found two instances with name {name}"
if not result:
return None
else:
return result[0] |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'extract_attr_for_match'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '7', 'type': 'block', 'children': ['8', '12', '37', '41', '52', '126', '141', '148']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'query_arg'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'for_statement', 'children': ['13', '16', '21']},{'id': '13', 'type': 'pattern_list', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'arg'},{'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': 'kwargs'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '20', 'type': 'argument_list', 'children': []},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'if_statement', 'children': ['23', '27']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': '=='},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '25', 'type': 'unary_operator', 'children': ['26'], 'value': '-'},{'id': '26', 'type': 'integer', 'children': [], 'value': '1'},{'id': '27', 'type': 'block', 'children': ['28', '33']},{'id': '28', 'type': 'assert_statement', 'children': ['29', '32']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'query_arg'},{'id': '31', 'type': 'None', 'children': []},{'id': '32', 'type': 'string', 'children': [], 'value': '"Only single query arg (-1 valued) is allowed"'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'query_arg'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '40', 'type': 'list', 'children': [], 'value': '[]'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'filterset'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'set'},{'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': 'kwargs'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '51', 'type': 'argument_list', 'children': []},{'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '55', 'type': 'block', 'children': ['56', '60', '85', '114']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '59', 'type': 'True', 'children': []},{'id': '60', 'type': 'assert_statement', 'children': ['61', '71']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'filterset'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '%'},{'id': '72', 'type': 'string', 'children': [], 'value': '"Filter set contained %s which was not in record %s"'},{'id': '73', 'type': 'tuple', 'children': ['74', '84']},{'id': '74', 'type': 'call', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'filterset'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'difference'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '85', 'type': 'for_statement', 'children': ['86', '87', '88']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '88', 'type': 'block', 'children': ['89', '95']},{'id': '89', 'type': 'if_statement', 'children': ['90', '93']},{'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': '=='},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'query_arg'},{'id': '93', 'type': 'block', 'children': ['94']},{'id': '94', 'type': 'continue_statement', 'children': []},{'id': '95', 'type': 'if_statement', 'children': ['96', '99']},{'id': '96', 'type': 'comparison_operator', 'children': ['97', '98'], 'value': 'in'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'if_statement', 'children': ['101', '108']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '105'], 'value': '!='},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'arg'},{'id': '108', 'type': 'block', 'children': ['109', '113']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'assignment', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '112', 'type': 'False', 'children': []},{'id': '113', 'type': 'break_statement', 'children': []},{'id': '114', 'type': 'if_statement', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'match'},{'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': 'result'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'query_arg'},{'id': '126', 'type': 'assert_statement', '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': 'result'},{'id': '132', 'type': 'integer', 'children': [], 'value': '1'},{'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '%'},{'id': '134', 'type': 'string', 'children': [], 'value': '"%d values matched %s, only allow 1"'},{'id': '135', 'type': 'tuple', 'children': ['136', '140']},{'id': '136', 'type': 'call', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '141', 'type': 'if_statement', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '143', 'type': 'block', 'children': ['144']},{'id': '144', 'type': 'return_statement', 'children': ['145']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '147', 'type': 'integer', 'children': [], 'value': '0'},{'id': '148', 'type': 'return_statement', 'children': ['149']},{'id': '149', 'type': 'None', 'children': []} | def extract_attr_for_match(items, **kwargs):
query_arg = None
for arg, value in kwargs.items():
if value == -1:
assert query_arg is None, "Only single query arg (-1 valued) is allowed"
query_arg = arg
result = []
filterset = set(kwargs.keys())
for item in items:
match = True
assert filterset.issubset(
item.keys()), "Filter set contained %s which was not in record %s" % (
filterset.difference(item.keys()),
item)
for arg in item:
if arg == query_arg:
continue
if arg in kwargs:
if item[arg] != kwargs[arg]:
match = False
break
if match:
result.append(item[query_arg])
assert len(result) <= 1, "%d values matched %s, only allow 1" % (
len(result), kwargs)
if result:
return result[0]
return None |
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_maybe_create_resources'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'typed_default_parameter', 'children': ['5', '6', '8']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'logging_task'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'Task'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '37', '118']},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '15']},{'id': '11', 'type': 'function_name', 'children': [], 'value': 'log'},{'id': '12', 'type': 'parameters', 'children': ['13']},{'id': '13', 'type': 'list_splat_pattern', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'if_statement', 'children': ['17', '18', '27']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'logging_task'},{'id': '18', 'type': 'block', 'children': ['19']},{'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': 'logging_task'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'list_splat', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '27', 'type': 'else_clause', 'children': ['28']},{'id': '28', 'type': 'block', 'children': ['29']},{'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': 'util'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'list_splat', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '37', 'type': 'function_definition', 'children': ['38', '39', '40']},{'id': '38', 'type': 'function_name', 'children': [], 'value': 'should_create_resources'},{'id': '39', 'type': 'parameters', 'children': []},{'id': '40', 'type': 'block', 'children': ['41', '49', '69', '77', '89', '95', '104', '116']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'get_prefix'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'if_statement', 'children': ['50', '61']},{'id': '50', 'type': 'comparison_operator', 'children': ['51', '56'], 'value': 'not'},{'id': '51', 'type': 'call', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'get_keypair_name'},{'id': '55', 'type': 'argument_list', 'children': []},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_keypair_dict'},{'id': '60', 'type': 'argument_list', 'children': []},{'id': '61', 'type': 'block', 'children': ['62', '67']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'string', 'children': [], 'value': 'f"Missing {u.get_keypair_name()} keypair, creating resources"'},{'id': '67', 'type': 'return_statement', 'children': ['68']},{'id': '68', 'type': 'True', 'children': []},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'vpcs'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'get_vpc_dict'},{'id': '76', 'type': 'argument_list', 'children': []},{'id': '77', 'type': 'if_statement', 'children': ['78', '81']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'not'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'vpcs'},{'id': '81', 'type': 'block', 'children': ['82', '87']},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'string', 'children': [], 'value': 'f"Missing {prefix} vpc, creating resources"'},{'id': '87', 'type': 'return_statement', 'children': ['88']},{'id': '88', 'type': 'True', 'children': []},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'vpc'},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'vpcs'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'gateways'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'u'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'get_gateway_dict'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'vpc'},{'id': '104', 'type': 'if_statement', 'children': ['105', '108']},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'not'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'gateways'},{'id': '108', 'type': 'block', 'children': ['109', '114']},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'call', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'string', 'children': [], 'value': 'f"Missing {prefix} gateway, creating resources"'},{'id': '114', 'type': 'return_statement', 'children': ['115']},{'id': '115', 'type': 'True', 'children': []},{'id': '116', 'type': 'return_statement', 'children': ['117']},{'id': '117', 'type': 'False', 'children': []},{'id': '118', 'type': 'try_statement', 'children': ['119', '243']},{'id': '119', 'type': 'block', 'children': ['120', '197', '216', '237']},{'id': '120', 'type': 'if_statement', 'children': ['121', '129']},{'id': '121', 'type': 'call', 'children': ['122', '127']},{'id': '122', 'type': 'attribute', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '127', 'type': 'argument_list', 'children': ['128']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'AWS_LOCK_FN'},{'id': '129', 'type': 'block', 'children': ['130', '149', '156', '165', '196']},{'id': '130', 'type': 'expression_statement', 'children': ['131']},{'id': '131', 'type': 'assignment', 'children': ['132', '136']},{'id': '132', 'type': 'pattern_list', 'children': ['133', '134', '135']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'pid'},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'lock_taskname'},{'id': '136', 'type': 'call', 'children': ['137', '147']},{'id': '137', 'type': 'attribute', 'children': ['138', '146']},{'id': '138', 'type': 'call', 'children': ['139', '145']},{'id': '139', 'type': 'attribute', 'children': ['140', '144']},{'id': '140', 'type': 'call', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '142', 'type': 'argument_list', 'children': ['143']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'AWS_LOCK_FN'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'read'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '147', 'type': 'argument_list', 'children': ['148']},{'id': '148', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'call', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '159', 'type': 'argument_list', 'children': ['160']},{'id': '160', 'type': 'concatenated_string', 'children': ['161', '162', '163', '164']},{'id': '161', 'type': 'string', 'children': [], 'value': 'f"waiting for aws resource creation, another resource initiation was "'},{'id': '162', 'type': 'string', 'children': [], 'value': 'f"initiated {int(time.time()-ts)} seconds ago by "'},{'id': '163', 'type': 'string', 'children': [], 'value': 'f"{lock_taskname}, delete lock file "'},{'id': '164', 'type': 'string', 'children': [], 'value': 'f"{AWS_LOCK_FN} if this is an error"'},{'id': '165', 'type': 'while_statement', 'children': ['166', '167']},{'id': '166', 'type': 'True', 'children': []},{'id': '167', 'type': 'block', 'children': ['168']},{'id': '168', 'type': 'if_statement', 'children': ['169', '177', '193']},{'id': '169', 'type': 'call', 'children': ['170', '175']},{'id': '170', 'type': 'attribute', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '175', 'type': 'argument_list', 'children': ['176']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'AWS_LOCK_FN'},{'id': '177', 'type': 'block', 'children': ['178', '185', '192']},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'call', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'concatenated_string', 'children': ['183', '184']},{'id': '183', 'type': 'string', 'children': [], 'value': 'f"waiting for lock file {AWS_LOCK_FN} to get deleted "'},{'id': '184', 'type': 'string', 'children': [], 'value': 'f"initiated {int(time.time()-ts)} seconds ago by "'},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '190']},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'sleep'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'integer', 'children': [], 'value': '2'},{'id': '192', 'type': 'continue_statement', 'children': []},{'id': '193', 'type': 'else_clause', 'children': ['194']},{'id': '194', 'type': 'block', 'children': ['195']},{'id': '195', 'type': 'break_statement', 'children': []},{'id': '196', 'type': 'return_statement', 'children': []},{'id': '197', 'type': 'with_statement', 'children': ['198', '208']},{'id': '198', 'type': 'with_clause', 'children': ['199']},{'id': '199', 'type': 'with_item', 'children': ['200']},{'id': '200', 'type': 'as_pattern', 'children': ['201', '206']},{'id': '201', 'type': 'call', 'children': ['202', '203']},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'open'},{'id': '203', 'type': 'argument_list', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'AWS_LOCK_FN'},{'id': '205', 'type': 'string', 'children': [], 'value': "'w'"},{'id': '206', 'type': 'as_pattern_target', 'children': ['207']},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '208', 'type': 'block', 'children': ['209']},{'id': '209', 'type': 'expression_statement', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '214']},{'id': '211', 'type': 'attribute', 'children': ['212', '213']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '214', 'type': 'argument_list', 'children': ['215']},{'id': '215', 'type': 'string', 'children': [], 'value': 'f\'{os.getpid()}-{int(time.time())}-{logging_task.name if logging_task else ""}\''},{'id': '216', 'type': 'if_statement', 'children': ['217', '221']},{'id': '217', 'type': 'not_operator', 'children': ['218']},{'id': '218', 'type': 'call', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'should_create_resources'},{'id': '220', 'type': 'argument_list', 'children': []},{'id': '221', 'type': 'block', 'children': ['222', '229', '236']},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'call', 'children': ['224', '227']},{'id': '224', 'type': 'attribute', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'log'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'string', 'children': [], 'value': '"Resources already created, no-op"'},{'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': 'os'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'AWS_LOCK_FN'},{'id': '236', 'type': 'return_statement', 'children': []},{'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': 'create_lib'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'create_resources'},{'id': '242', 'type': 'argument_list', 'children': []},{'id': '243', 'type': 'finally_clause', 'children': ['244']},{'id': '244', 'type': 'block', 'children': ['245']},{'id': '245', 'type': 'if_statement', 'children': ['246', '254']},{'id': '246', 'type': 'call', 'children': ['247', '252']},{'id': '247', 'type': 'attribute', 'children': ['248', '251']},{'id': '248', 'type': 'attribute', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'exists'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'AWS_LOCK_FN'},{'id': '254', 'type': 'block', 'children': ['255']},{'id': '255', 'type': 'expression_statement', 'children': ['256']},{'id': '256', 'type': 'call', 'children': ['257', '260']},{'id': '257', 'type': 'attribute', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '260', 'type': 'argument_list', 'children': ['261']},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'AWS_LOCK_FN'} | def _maybe_create_resources(logging_task: Task = None):
def log(*args):
if logging_task:
logging_task.log(*args)
else:
util.log(*args)
def should_create_resources():
prefix = u.get_prefix()
if u.get_keypair_name() not in u.get_keypair_dict():
log(f"Missing {u.get_keypair_name()} keypair, creating resources")
return True
vpcs = u.get_vpc_dict()
if prefix not in vpcs:
log(f"Missing {prefix} vpc, creating resources")
return True
vpc = vpcs[prefix]
gateways = u.get_gateway_dict(vpc)
if prefix not in gateways:
log(f"Missing {prefix} gateway, creating resources")
return True
return False
try:
if os.path.exists(AWS_LOCK_FN):
pid, ts, lock_taskname = open(AWS_LOCK_FN).read().split('-')
ts = int(ts)
log(f"waiting for aws resource creation, another resource initiation was "
f"initiated {int(time.time()-ts)} seconds ago by "
f"{lock_taskname}, delete lock file "
f"{AWS_LOCK_FN} if this is an error")
while True:
if os.path.exists(AWS_LOCK_FN):
log(f"waiting for lock file {AWS_LOCK_FN} to get deleted "
f"initiated {int(time.time()-ts)} seconds ago by ")
time.sleep(2)
continue
else:
break
return
with open(AWS_LOCK_FN, 'w') as f:
f.write(
f'{os.getpid()}-{int(time.time())}-{logging_task.name if logging_task else ""}')
if not should_create_resources():
util.log("Resources already created, no-op")
os.remove(AWS_LOCK_FN)
return
create_lib.create_resources()
finally:
if os.path.exists(AWS_LOCK_FN):
os.remove(AWS_LOCK_FN) |
Subsets and Splits