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', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_child_type_choices'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '7', 'type': 'block', 'children': ['8', '23', '33', '37', '41', '118']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '11', 'type': 'call', 'children': ['12', '20']},{'id': '12', 'type': 'attribute', 'children': ['13', '18', '19']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'ChildModelPluginPolymorphicParentModelAdmin'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'get_child_type_choices'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'plugins'},{'id': '26', 'type': 'call', 'children': ['27', '32']},{'id': '27', 'type': 'attribute', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'child_model_plugin_class'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'get_plugins'},{'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': 'labels'},{'id': '36', 'type': 'dictionary', 'children': []},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'assignment', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort_priorities'},{'id': '40', 'type': 'dictionary', 'children': []},{'id': '41', 'type': 'if_statement', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'plugins'},{'id': '43', 'type': 'block', 'children': ['44', '80', '94']},{'id': '44', 'type': 'for_statement', 'children': ['45', '46', '47']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'plugins'},{'id': '47', 'type': 'block', 'children': ['48', '56', '67']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'content_type'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'assignment', 'children': ['58', '61']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '61', 'type': 'call', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'capfirst'},{'id': '63', 'type': 'argument_list', 'children': ['64']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'verbose_name'},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'assignment', 'children': ['69', '72']},{'id': '69', 'type': 'subscript', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'sort_priorities'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76', '77']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'plugin'},{'id': '76', 'type': 'string', 'children': [], 'value': "'sort_priority'"},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'pk'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '83', 'type': 'list_comprehension', 'children': ['84', '89']},{'id': '84', 'type': 'tuple', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'labels'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '89', 'type': 'for_in_clause', 'children': ['90', '93']},{'id': '90', 'type': 'pattern_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'ctype'},{'id': '92', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '94', 'type': 'return_statement', 'children': ['95']},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'choices'},{'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '101', 'type': 'lambda', 'children': ['102', '105']},{'id': '102', 'type': 'lambda_parameters', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '105', 'type': 'call', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '107', 'type': 'argument_list', 'children': ['108', '113']},{'id': '108', 'type': 'subscript', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'sort_priorities'},{'id': '110', 'type': 'subscript', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '112', 'type': 'integer', 'children': [], 'value': '0'},{'id': '113', 'type': 'subscript', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'sort_priorities'},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'b'},{'id': '117', 'type': 'integer', 'children': [], 'value': '0'},{'id': '118', 'type': 'return_statement', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'choices'}
def get_child_type_choices(self, request, action): choices = super(ChildModelPluginPolymorphicParentModelAdmin, self) \ .get_child_type_choices(request, action) plugins = self.child_model_plugin_class.get_plugins() labels = {} sort_priorities = {} if plugins: for plugin in plugins: pk = plugin.content_type.pk labels[pk] = capfirst(plugin.verbose_name) sort_priorities[pk] = getattr(plugin, 'sort_priority', labels[pk]) choices = [(ctype, labels[ctype]) for ctype, _ in choices] return sorted(choices, cmp=lambda a, b: cmp( sort_priorities[a[0]], sort_priorities[b[0]] ) ) return choices
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_sorted_apps'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'admin_apps'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'block', 'children': ['7', '11', '53', '57', '67', '75']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted_apps'},{'id': '10', 'type': 'list', 'children': [], 'value': '[]'},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'orig_app_spec'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'appsettings'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'DASHBOARD_SORTED_APPS'},{'id': '16', 'type': 'block', 'children': ['17', '25', '41']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'app_spec'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'orig_app_spec'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '30']},{'id': '27', 'type': 'subscript', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'app_spec'},{'id': '29', 'type': 'string', 'children': [], 'value': "'models'"},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': '_build_app_models'},{'id': '32', 'type': 'argument_list', 'children': ['33', '34', '35', '38']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'admin_apps'},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'app_spec'},{'id': '37', 'type': 'string', 'children': [], 'value': "'models'"},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ensure_all_models'},{'id': '40', 'type': 'True', 'children': []},{'id': '41', 'type': 'if_statement', 'children': ['42', '45']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'app_spec'},{'id': '44', 'type': 'string', 'children': [], 'value': "'models'"},{'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': 'sorted_apps'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'app_spec'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'used_models'},{'id': '56', 'type': 'list', 'children': [], 'value': '[]'},{'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'sorted_apps'},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'augmented_assignment', 'children': ['63', '64'], 'value': '+='},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'used_models'},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'app'},{'id': '66', 'type': 'string', 'children': [], 'value': "'models'"},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'augmented_assignment', 'children': ['69', '70'], 'value': '+='},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sorted_apps'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': '_remove_app_models'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'admin_apps'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'used_models'},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'sorted_apps'}
def filter_sorted_apps(admin_apps, request): sorted_apps = [] for orig_app_spec in appsettings.DASHBOARD_SORTED_APPS: app_spec = orig_app_spec.copy() app_spec['models'] = _build_app_models( request, admin_apps, app_spec['models'], ensure_all_models=True ) if app_spec['models']: sorted_apps.append(app_spec) used_models = [] for app in sorted_apps: used_models += app['models'] sorted_apps += _remove_app_models(admin_apps, used_models) return sorted_apps
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'render_stats'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '7', 'type': 'block', 'children': ['8', '14', '29', '37', '45']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'StdoutWrapper'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'if_statement', 'children': ['15', '20']},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '17', 'type': 'argument_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '19', 'type': 'string', 'children': [], 'value': '"stream"'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'stream'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'stream'},{'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': 'stats'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'sort_stats'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'list_splat', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '37', 'type': 'expression_statement', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '44']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '44', 'type': 'argument_list', 'children': []},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'stream'}
def render_stats(stats, sort, format): output = StdoutWrapper() if hasattr(stats, "stream"): stats.stream = output.stream stats.sort_stats(*sort) getattr(stats, format)() return output.stream
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'render_queries'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '6', 'type': 'block', 'children': ['7', '13', '40', '99', '103', '107', '156', '173', '196']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'StringIO'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'if_statement', 'children': ['14', '17']},{'id': '14', 'type': 'comparison_operator', 'children': ['15', '16'], 'value': '=='},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '16', 'type': 'string', 'children': [], 'value': "'order'"},{'id': '17', 'type': 'block', 'children': ['18', '22', '38']},{'id': '18', 'type': 'print_statement', 'children': ['19', '21']},{'id': '19', 'type': 'chevron', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '21', 'type': 'string', 'children': [], 'value': '" time query"'},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '25']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'print_statement', 'children': ['27', '29']},{'id': '27', 'type': 'chevron', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '%'},{'id': '30', 'type': 'string', 'children': [], 'value': '" %8s %s"'},{'id': '31', 'type': 'tuple', 'children': ['32', '35']},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '34', 'type': 'string', 'children': [], 'value': '"time"'},{'id': '35', 'type': 'subscript', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '37', 'type': 'string', 'children': [], 'value': '"sql"'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '40', 'type': 'if_statement', 'children': ['41', '44', '65', '90']},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '=='},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '43', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'function_definition', 'children': ['46', '47', '50']},{'id': '46', 'type': 'function_name', 'children': [], 'value': 'sorter'},{'id': '47', 'type': 'parameters', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '50', 'type': 'block', 'children': ['51']},{'id': '51', 'type': 'return_statement', 'children': ['52']},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '54', 'type': 'argument_list', 'children': ['55', '60']},{'id': '55', 'type': 'subscript', 'children': ['56', '59']},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '58', 'type': 'integer', 'children': [], 'value': '1'},{'id': '59', 'type': 'integer', 'children': [], 'value': '1'},{'id': '60', 'type': 'subscript', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'integer', 'children': [], 'value': '1'},{'id': '65', 'type': 'elif_clause', 'children': ['66', '69']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': '=='},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '68', 'type': 'string', 'children': [], 'value': "'queries'"},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'function_definition', 'children': ['71', '72', '75']},{'id': '71', 'type': 'function_name', 'children': [], 'value': 'sorter'},{'id': '72', 'type': 'parameters', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '75', 'type': 'block', 'children': ['76']},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '79', 'type': 'argument_list', 'children': ['80', '85']},{'id': '80', 'type': 'subscript', 'children': ['81', '84']},{'id': '81', 'type': 'subscript', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '83', 'type': 'integer', 'children': [], 'value': '1'},{'id': '84', 'type': 'integer', 'children': [], 'value': '0'},{'id': '85', 'type': 'subscript', 'children': ['86', '89']},{'id': '86', 'type': 'subscript', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '88', 'type': 'integer', 'children': [], 'value': '1'},{'id': '89', 'type': 'integer', 'children': [], 'value': '0'},{'id': '90', 'type': 'else_clause', 'children': ['91']},{'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': 'RuntimeError'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'binary_operator', 'children': ['97', '98'], 'value': '%'},{'id': '97', 'type': 'string', 'children': [], 'value': '"Unknown sort: %s"'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '99', 'type': 'print_statement', 'children': ['100', '102']},{'id': '100', 'type': 'chevron', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '102', 'type': 'string', 'children': [], 'value': '" queries time query"'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '106', 'type': 'dictionary', 'children': []},{'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '110', 'type': 'block', 'children': ['111']},{'id': '111', 'type': 'try_statement', 'children': ['112', '138']},{'id': '112', 'type': 'block', 'children': ['113', '121', '127']},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '116', 'type': 'subscript', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '120', 'type': 'string', 'children': [], 'value': '"sql"'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'augmented_assignment', 'children': ['123', '126'], 'value': '+='},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '125', 'type': 'integer', 'children': [], 'value': '0'},{'id': '126', 'type': 'integer', 'children': [], 'value': '1'},{'id': '127', 'type': 'expression_statement', 'children': ['128']},{'id': '128', 'type': 'augmented_assignment', 'children': ['129', '132'], 'value': '+='},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '131', 'type': 'integer', 'children': [], 'value': '1'},{'id': '132', 'type': 'call', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'Decimal'},{'id': '134', 'type': 'argument_list', 'children': ['135']},{'id': '135', 'type': 'subscript', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '137', 'type': 'string', 'children': [], 'value': '"time"'},{'id': '138', 'type': 'except_clause', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '140', 'type': 'block', 'children': ['141']},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '148']},{'id': '143', 'type': 'subscript', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '147', 'type': 'string', 'children': [], 'value': '"sql"'},{'id': '148', 'type': 'list', 'children': ['149', '150'], 'value': '[1, Decimal(query["time"])]'},{'id': '149', 'type': 'integer', 'children': [], 'value': '1'},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'Decimal'},{'id': '152', 'type': 'argument_list', 'children': ['153']},{'id': '153', 'type': 'subscript', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '155', 'type': 'string', 'children': [], 'value': '"time"'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '159', 'type': 'call', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '161', 'type': 'argument_list', 'children': ['162', '167', '170']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '166', 'type': 'argument_list', 'children': []},{'id': '167', 'type': 'keyword_argument', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'sorter'},{'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '172', 'type': 'True', 'children': []},{'id': '173', 'type': 'for_statement', 'children': ['174', '175', '176']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'results'},{'id': '176', 'type': 'block', 'children': ['177']},{'id': '177', 'type': 'print_statement', 'children': ['178', '180']},{'id': '178', 'type': 'chevron', 'children': ['179']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '%'},{'id': '181', 'type': 'string', 'children': [], 'value': '" %8d %8.3f %s"'},{'id': '182', 'type': 'tuple', 'children': ['183', '188', '193']},{'id': '183', 'type': 'subscript', 'children': ['184', '187']},{'id': '184', 'type': 'subscript', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '186', 'type': 'integer', 'children': [], 'value': '1'},{'id': '187', 'type': 'integer', 'children': [], 'value': '0'},{'id': '188', 'type': 'subscript', 'children': ['189', '192']},{'id': '189', 'type': 'subscript', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '191', 'type': 'integer', 'children': [], 'value': '1'},{'id': '192', 'type': 'integer', 'children': [], 'value': '1'},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '195', 'type': 'integer', 'children': [], 'value': '0'},{'id': '196', 'type': 'return_statement', 'children': ['197']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'output'}
def render_queries(queries, sort): output = StringIO() if sort == 'order': print >>output, " time query" for query in queries: print >>output, " %8s %s" % (query["time"], query["sql"]) return output if sort == 'time': def sorter(x, y): return cmp(x[1][1], y[1][1]) elif sort == 'queries': def sorter(x, y): return cmp(x[1][0], y[1][0]) else: raise RuntimeError("Unknown sort: %s" % sort) print >>output, " queries time query" results = {} for query in queries: try: result = results[query["sql"]] result[0] += 1 result[1] += Decimal(query["time"]) except KeyError: results[query["sql"]] = [1, Decimal(query["time"])] results = sorted(results.iteritems(), cmp=sorter, reverse=True) for result in results: print >>output, " %8d %8.3f %s" % ( result[1][0], result[1][1], result[0] ) return output
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_request'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'block', 'children': ['7', '50', '83']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'unpickle'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '11', 'type': 'block', 'children': ['12', '28', '46']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '15', 'type': 'call', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'unpickle_stats'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'b64decode'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': "'stats'"},{'id': '27', 'type': 'string', 'children': [], 'value': "''"},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'cPickle'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'loads'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'b64decode'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '43']},{'id': '40', 'type': 'attribute', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'string', 'children': [], 'value': "'queries'"},{'id': '45', 'type': 'string', 'children': [], 'value': "''"},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'expression_list', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '50', 'type': 'if_statement', 'children': ['51', '81']},{'id': '51', 'type': 'boolean_operator', 'children': ['52', '57', '58'], 'value': 'and'},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '56'], 'value': '!='},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '56', 'type': 'string', 'children': [], 'value': "'GET'"},{'id': '57', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '58', 'type': 'not_operator', 'children': ['59']},{'id': '59', 'type': '()', 'children': ['60']},{'id': '60', 'type': 'comparison_operator', 'children': ['61', '78'], 'value': 'in'},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'META'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '67', 'type': 'argument_list', 'children': ['68', '69']},{'id': '68', 'type': 'string', 'children': [], 'value': "'HTTP_CONTENT_TYPE'"},{'id': '69', 'type': 'call', 'children': ['70', '75']},{'id': '70', 'type': 'attribute', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'META'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': "'CONTENT_TYPE'"},{'id': '77', 'type': 'string', 'children': [], 'value': "''"},{'id': '78', 'type': 'list', 'children': ['79', '80'], 'value': "['multipart/form-data', 'application/x-www-form-urlencoded']"},{'id': '79', 'type': 'string', 'children': [], 'value': "'multipart/form-data'"},{'id': '80', 'type': 'string', 'children': [], 'value': "'application/x-www-form-urlencoded'"},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'return_statement', 'children': []},{'id': '83', 'type': 'if_statement', 'children': ['84', '107']},{'id': '84', 'type': '()', 'children': ['85']},{'id': '85', 'type': 'boolean_operator', 'children': ['86', '95'], 'value': 'and'},{'id': '86', 'type': 'call', 'children': ['87', '92']},{'id': '87', 'type': 'attribute', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'REQUEST'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'string', 'children': [], 'value': "'profile'"},{'id': '94', 'type': 'False', 'children': []},{'id': '95', 'type': '()', 'children': ['96']},{'id': '96', 'type': 'boolean_operator', 'children': ['97', '102'], 'value': 'or'},{'id': '97', 'type': 'comparison_operator', 'children': ['98', '101'], 'value': '=='},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'settings'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'DEBUG'},{'id': '101', 'type': 'True', 'children': []},{'id': '102', 'type': 'attribute', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'is_staff'},{'id': '107', 'type': 'block', 'children': ['108', '118', '124']},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '113']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'statsfile'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'tempfile'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'NamedTemporaryFile'},{'id': '117', 'type': 'argument_list', 'children': []},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '121', 'type': 'attribute', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'REQUEST'},{'id': '124', 'type': 'if_statement', 'children': ['125', '143', '160', '196']},{'id': '125', 'type': '()', 'children': ['126']},{'id': '126', 'type': 'boolean_operator', 'children': ['127', '134'], 'value': 'and'},{'id': '127', 'type': 'call', 'children': ['128', '131']},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '131', 'type': 'argument_list', 'children': ['132', '133']},{'id': '132', 'type': 'string', 'children': [], 'value': "'show_stats'"},{'id': '133', 'type': 'False', 'children': []},{'id': '134', 'type': 'comparison_operator', 'children': ['135', '142'], 'value': '=='},{'id': '135', 'type': 'call', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'string', 'children': [], 'value': "'show_queries'"},{'id': '141', 'type': 'string', 'children': [], 'value': "'1'"},{'id': '142', 'type': 'string', 'children': [], 'value': "'1'"},{'id': '143', 'type': 'block', 'children': ['144', '153']},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '149']},{'id': '146', 'type': 'pattern_list', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'unpickle'},{'id': '151', 'type': 'argument_list', 'children': ['152']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '153', 'type': 'return_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'display_stats'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158', '159']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '160', 'type': 'elif_clause', 'children': ['161', '179']},{'id': '161', 'type': '()', 'children': ['162']},{'id': '162', 'type': 'boolean_operator', 'children': ['163', '170'], 'value': 'and'},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '167', 'type': 'argument_list', 'children': ['168', '169']},{'id': '168', 'type': 'string', 'children': [], 'value': "'show_queries'"},{'id': '169', 'type': 'False', 'children': []},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '178'], 'value': '=='},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177']},{'id': '176', 'type': 'string', 'children': [], 'value': "'show_stats'"},{'id': '177', 'type': 'string', 'children': [], 'value': "'1'"},{'id': '178', 'type': 'string', 'children': [], 'value': "'1'"},{'id': '179', 'type': 'block', 'children': ['180', '189']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'assignment', 'children': ['182', '185']},{'id': '182', 'type': 'pattern_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '185', 'type': 'call', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'unpickle'},{'id': '187', 'type': 'argument_list', 'children': ['188']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '189', 'type': 'return_statement', 'children': ['190']},{'id': '190', 'type': 'call', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'display_queries'},{'id': '192', 'type': 'argument_list', 'children': ['193', '194', '195']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'stats'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'queries'},{'id': '196', 'type': 'else_clause', 'children': ['197']},{'id': '197', 'type': 'block', 'children': ['198', '213']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'profiler'},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'hotshot'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'Profile'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'attribute', 'children': ['209', '212']},{'id': '209', 'type': 'attribute', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'statsfile'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '213', 'type': 'expression_statement', 'children': ['214']},{'id': '214', 'type': 'call', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'reset_queries'},{'id': '216', 'type': 'argument_list', 'children': []}
def process_request(self, request): def unpickle(params): stats = unpickle_stats(b64decode(params.get('stats', ''))) queries = cPickle.loads(b64decode(params.get('queries', ''))) return stats, queries if request.method != 'GET' and \ not (request.META.get( 'HTTP_CONTENT_TYPE', request.META.get('CONTENT_TYPE', '') ) in ['multipart/form-data', 'application/x-www-form-urlencoded']): return if (request.REQUEST.get('profile', False) and (settings.DEBUG == True or request.user.is_staff)): request.statsfile = tempfile.NamedTemporaryFile() params = request.REQUEST if (params.get('show_stats', False) and params.get('show_queries', '1') == '1'): stats, queries = unpickle(params) return display_stats(request, stats, queries) elif (params.get('show_queries', False) and params.get('show_stats', '1') == '1'): stats, queries = unpickle(params) return display_queries(request, stats, queries) else: request.profiler = hotshot.Profile(request.statsfile.name) reset_queries()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'dedupe_and_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'block', 'children': ['12', '18', '24', '36', '56', '71']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '15', 'type': 'boolean_operator', 'children': ['16', '17'], 'value': 'or'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'first'},{'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': 'last'},{'id': '21', 'type': 'boolean_operator', 'children': ['22', '23'], 'value': 'or'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'last'},{'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': 'new_sequence'},{'id': '27', 'type': 'list_comprehension', 'children': ['28', '29', '32']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '29', 'type': 'for_in_clause', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'first'},{'id': '32', 'type': 'if_clause', 'children': ['33']},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': 'in'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '36', 'type': 'for_statement', 'children': ['37', '38', '39']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '39', 'type': 'block', 'children': ['40']},{'id': '40', 'type': 'if_statement', 'children': ['41', '48']},{'id': '41', 'type': 'boolean_operator', 'children': ['42', '45'], 'value': 'and'},{'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'not'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'new_sequence'},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'not'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'last'},{'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': 'new_sequence'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'new_sequence'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'list_comprehension', 'children': ['63', '64', '67']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'last'},{'id': '67', 'type': 'if_clause', 'children': ['68']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'in'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'call', 'children': ['73', '77']},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'sequence'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'new_sequence'}
def dedupe_and_sort(sequence, first=None, last=None): first = first or [] last = last or [] new_sequence = [i for i in first if i in sequence] for item in sequence: if item not in new_sequence and item not in last: new_sequence.append(item) new_sequence.extend([i for i in last if i in sequence]) return type(sequence)(new_sequence)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortedSemver'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '7', 'type': 'string', 'children': [], 'value': '"asc"'},{'id': '8', 'type': 'block', 'children': ['9']},{'id': '9', 'type': 'if_statement', 'children': ['10', '19', '77']},{'id': '10', 'type': 'boolean_operator', 'children': ['11', '12'], 'value': 'and'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '14', 'type': 'argument_list', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '16', 'type': 'tuple', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'if_statement', 'children': ['21', '22', '45']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'PY2'},{'id': '22', 'type': 'block', 'children': ['23']},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28', '33']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'cmp'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'semver'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'compare'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '35', 'type': 'conditional_expression', 'children': ['36', '37', '44'], 'value': 'if'},{'id': '36', 'type': 'True', 'children': []},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '43'], 'value': '=='},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'string', 'children': [], 'value': '"DESC"'},{'id': '44', 'type': 'False', 'children': []},{'id': '45', 'type': 'else_clause', 'children': ['46']},{'id': '46', 'type': 'block', 'children': ['47', '52']},{'id': '47', 'type': 'import_from_statement', 'children': ['48', '50']},{'id': '48', 'type': 'dotted_name', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'functools'},{'id': '50', 'type': 'dotted_name', 'children': ['51']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'cmp_to_key'},{'id': '52', 'type': 'return_statement', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '55', 'type': 'argument_list', 'children': ['56', '57', '65']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'versions'},{'id': '57', 'type': 'keyword_argument', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'cmp_to_key'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'semver'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'compare'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '67', 'type': 'conditional_expression', 'children': ['68', '69', '76'], 'value': 'if'},{'id': '68', 'type': 'True', 'children': []},{'id': '69', 'type': 'comparison_operator', 'children': ['70', '75'], 'value': '=='},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'string', 'children': [], 'value': '"DESC"'},{'id': '76', 'type': 'False', 'children': []},{'id': '77', 'type': 'else_clause', 'children': ['78']},{'id': '78', 'type': 'block', 'children': ['79']},{'id': '79', 'type': 'raise_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'string', 'children': [], 'value': '"Invaild Versions, a list or tuple is right."'}
def sortedSemver(versions, sort="asc"): if versions and isinstance(versions, (list, tuple)): if PY2: return sorted(versions, cmp=semver.compare, reverse=True if sort.upper() == "DESC" else False) else: from functools import cmp_to_key return sorted(versions, key=cmp_to_key(semver.compare), reverse=True if sort.upper() == "DESC" else False) else: raise TypeError("Invaild Versions, a list or tuple is right.")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'unique'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'tolerance'},{'id': '7', 'type': 'float', 'children': [], 'value': '1e-6'},{'id': '8', 'type': 'type', 'children': ['9']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '12', 'type': 'block', 'children': ['13', '24', '28', '102']},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'unique'},{'id': '27', 'type': 'list', 'children': [], 'value': '[]'},{'id': '28', 'type': 'while_statement', 'children': ['29', '35']},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '34'], 'value': '>'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'block', 'children': ['36', '42', '61', '83', '95']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '39', 'type': 'subscript', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '41', 'type': 'integer', 'children': [], 'value': '0'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'lis'},{'id': '45', 'type': 'list_comprehension', 'children': ['46', '47', '50']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '50', 'type': 'if_clause', 'children': ['51']},{'id': '51', 'type': 'comparison_operator', 'children': ['52', '60'], 'value': '<'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '-'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'current'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'tolerance'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '64', 'type': 'list_comprehension', 'children': ['65', '66', '69']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '69', 'type': 'if_clause', 'children': ['70']},{'id': '70', 'type': 'not_operator', 'children': ['71']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '82'], 'value': '<'},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'abs'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'binary_operator', 'children': ['78', '81'], 'value': '-'},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'lis'},{'id': '80', 'type': 'integer', 'children': [], 'value': '0'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'tolerance'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'xi_lis_average'},{'id': '86', 'type': 'binary_operator', 'children': ['87', '91'], 'value': '/'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'lis'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'lis'},{'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': 'unique'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'xi_lis_average'},{'id': '102', 'type': 'return_statement', 'children': ['103']},{'id': '103', 'type': 'call', 'children': ['104', '107']},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '107', 'type': 'argument_list', 'children': ['108']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'unique'}
def unique(arr, tolerance=1e-6) -> np.ndarray: arr = sorted(arr.flatten()) unique = [] while len(arr) > 0: current = arr[0] lis = [xi for xi in arr if np.abs(current - xi) < tolerance] arr = [xi for xi in arr if not np.abs(lis[0] - xi) < tolerance] xi_lis_average = sum(lis) / len(lis) unique.append(xi_lis_average) return np.array(unique)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_cache_key'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '19', '25', '31', '58']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '18']},{'id': '13', 'type': 'attribute', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'cache_key'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '30', 'type': 'argument_list', 'children': []},{'id': '31', 'type': 'for_statement', 'children': ['32', '33', '34']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'if_statement', 'children': ['36', '47']},{'id': '36', 'type': 'boolean_operator', 'children': ['37', '44'], 'value': 'and'},{'id': '37', 'type': 'boolean_operator', 'children': ['38', '41'], 'value': 'and'},{'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '!='},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '40', 'type': 'string', 'children': [], 'value': '"api_sig"'},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '!='},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '43', 'type': 'string', 'children': [], 'value': '"api_key"'},{'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': '!='},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '46', 'type': 'string', 'children': [], 'value': '"sk"'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'augmented_assignment', 'children': ['50', '51'], 'value': '+='},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'cache_key'},{'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '+'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '53', 'type': 'subscript', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '58', 'type': 'return_statement', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '73']},{'id': '60', 'type': 'attribute', 'children': ['61', '72']},{'id': '61', 'type': 'call', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sha1'},{'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': 'cache_key'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'string', 'children': [], 'value': '"utf-8"'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '73', 'type': 'argument_list', 'children': []}
def _get_cache_key(self): keys = list(self.params.keys()) keys.sort() cache_key = str() for key in keys: if key != "api_sig" and key != "api_key" and key != "sk": cache_key += key + self.params[key] return hashlib.sha1(cache_key.encode("utf-8")).hexdigest()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fast_float'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '11', '14', '19', '22']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'lambda', 'children': ['8', '10']},{'id': '8', 'type': 'lambda_parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'nan'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_uni'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'unicodedata'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'numeric'},{'id': '19', 'type': 'default_parameter', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_nan_inf'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'NAN_INF'},{'id': '22', 'type': 'default_parameter', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': '_first_char'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'POTENTIAL_FIRST_CHAR'},{'id': '25', 'type': 'block', 'children': ['26']},{'id': '26', 'type': 'if_statement', 'children': ['27', '44', '98']},{'id': '27', 'type': 'boolean_operator', 'children': ['28', '33'], 'value': 'or'},{'id': '28', 'type': 'comparison_operator', 'children': ['29', '32'], 'value': 'in'},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '31', 'type': 'integer', 'children': [], 'value': '0'},{'id': '32', 'type': 'identifier', 'children': [], 'value': '_first_char'},{'id': '33', 'type': 'comparison_operator', 'children': ['34', '43'], 'value': 'in'},{'id': '34', 'type': 'subscript', 'children': ['35', '40']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '39', 'type': 'argument_list', 'children': []},{'id': '40', 'type': 'slice', 'children': ['41', '42']},{'id': '41', 'type': 'colon', 'children': []},{'id': '42', 'type': 'integer', 'children': [], 'value': '3'},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_nan_inf'},{'id': '44', 'type': 'block', 'children': ['45']},{'id': '45', 'type': 'try_statement', 'children': ['46', '65']},{'id': '46', 'type': 'block', 'children': ['47', '54']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '54', 'type': 'return_statement', 'children': ['55']},{'id': '55', 'type': 'conditional_expression', 'children': ['56', '57', '64'], 'value': 'if'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'nan'},{'id': '57', 'type': 'boolean_operator', 'children': ['58', '61'], 'value': 'and'},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'nan'},{'id': '60', 'type': 'None', 'children': []},{'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': '!='},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '65', 'type': 'except_clause', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'try_statement', 'children': ['69', '90']},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'return_statement', 'children': ['71']},{'id': '71', 'type': 'conditional_expression', 'children': ['72', '80', '86'], 'value': 'if'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': '_uni'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'x'},{'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': 'x'},{'id': '85', 'type': 'integer', 'children': [], 'value': '1'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '90', 'type': 'except_clause', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'return_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '98', 'type': 'else_clause', 'children': ['99']},{'id': '99', 'type': 'block', 'children': ['100']},{'id': '100', 'type': 'try_statement', 'children': ['101', '122']},{'id': '101', 'type': 'block', 'children': ['102']},{'id': '102', 'type': 'return_statement', 'children': ['103']},{'id': '103', 'type': 'conditional_expression', 'children': ['104', '112', '118'], 'value': 'if'},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': '_uni'},{'id': '106', 'type': 'argument_list', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '108', 'type': 'call', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '112', 'type': 'comparison_operator', 'children': ['113', '117'], 'value': '=='},{'id': '113', 'type': 'call', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '117', 'type': 'integer', 'children': [], 'value': '1'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '122', 'type': 'except_clause', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '124', 'type': 'block', 'children': ['125']},{'id': '125', 'type': 'return_statement', 'children': ['126']},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '128', 'type': 'argument_list', 'children': ['129']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'x'}
def fast_float( x, key=lambda x: x, nan=None, _uni=unicodedata.numeric, _nan_inf=NAN_INF, _first_char=POTENTIAL_FIRST_CHAR, ): if x[0] in _first_char or x.lstrip()[:3] in _nan_inf: try: x = float(x) return nan if nan is not None and x != x else x except ValueError: try: return _uni(x, key(x)) if len(x) == 1 else key(x) except TypeError: return key(x) else: try: return _uni(x, key(x)) if len(x) == 1 else key(x) except TypeError: return key(x)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'fast_int'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '11', '16']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'lambda', 'children': ['8', '10']},{'id': '8', 'type': 'lambda_parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': '_uni'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'unicodedata'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'digit'},{'id': '16', 'type': 'default_parameter', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': '_first_char'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'POTENTIAL_FIRST_CHAR'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'if_statement', 'children': ['21', '26', '67']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': 'in'},{'id': '22', 'type': 'subscript', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '24', 'type': 'integer', 'children': [], 'value': '0'},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_first_char'},{'id': '26', 'type': 'block', 'children': ['27']},{'id': '27', 'type': 'try_statement', 'children': ['28', '34']},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'return_statement', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'long'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '34', 'type': 'except_clause', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'try_statement', 'children': ['38', '59']},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'return_statement', 'children': ['40']},{'id': '40', 'type': 'conditional_expression', 'children': ['41', '49', '55'], 'value': 'if'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': '_uni'},{'id': '43', 'type': 'argument_list', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '54'], 'value': '=='},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '54', 'type': 'integer', 'children': [], 'value': '1'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '59', 'type': 'except_clause', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'return_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '67', 'type': 'else_clause', 'children': ['68']},{'id': '68', 'type': 'block', 'children': ['69']},{'id': '69', 'type': 'try_statement', 'children': ['70', '91']},{'id': '70', 'type': 'block', 'children': ['71']},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'conditional_expression', 'children': ['73', '81', '87'], 'value': 'if'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_uni'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '81', 'type': 'comparison_operator', 'children': ['82', '86'], 'value': '=='},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '86', 'type': 'integer', 'children': [], 'value': '1'},{'id': '87', 'type': 'call', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '91', 'type': 'except_clause', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'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': 'key'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'x'}
def fast_int( x, key=lambda x: x, _uni=unicodedata.digit, _first_char=POTENTIAL_FIRST_CHAR, ): if x[0] in _first_char: try: return long(x) except ValueError: try: return _uni(x, key(x)) if len(x) == 1 else key(x) except TypeError: return key(x) else: try: return _uni(x, key(x)) if len(x) == 1 else key(x) except TypeError: return key(x)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_and_print_entries'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '6', 'type': 'block', 'children': ['7', '19', '33', '84', '98', '270']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'is_float'},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '14'], 'value': 'in'},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'number_type'},{'id': '14', 'type': 'tuple', 'children': ['15', '16', '17', '18']},{'id': '15', 'type': 'string', 'children': [], 'value': '"float"'},{'id': '16', 'type': 'string', 'children': [], 'value': '"real"'},{'id': '17', 'type': 'string', 'children': [], 'value': '"f"'},{'id': '18', 'type': 'string', 'children': [], 'value': '"r"'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'signed'},{'id': '22', 'type': 'boolean_operator', 'children': ['23', '26'], 'value': 'or'},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'signed'},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '30'], 'value': 'in'},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'number_type'},{'id': '30', 'type': 'tuple', 'children': ['31', '32']},{'id': '31', 'type': 'string', 'children': [], 'value': '"real"'},{'id': '32', 'type': 'string', 'children': [], 'value': '"r"'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '36', 'type': '()', 'children': ['37']},{'id': '37', 'type': 'binary_operator', 'children': ['38', '75'], 'value': '|'},{'id': '38', 'type': 'binary_operator', 'children': ['39', '66'], 'value': '|'},{'id': '39', 'type': 'binary_operator', 'children': ['40', '55'], 'value': '|'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '48'], 'value': '|'},{'id': '41', 'type': 'binary_operator', 'children': ['42', '47'], 'value': '*'},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'FLOAT'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'is_float'},{'id': '48', 'type': 'binary_operator', 'children': ['49', '54'], 'value': '*'},{'id': '49', 'type': 'attribute', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'SIGNED'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'signed'},{'id': '55', 'type': 'binary_operator', 'children': ['56', '61'], 'value': '*'},{'id': '56', 'type': 'attribute', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'NOEXP'},{'id': '61', 'type': '()', 'children': ['62']},{'id': '62', 'type': 'not_operator', 'children': ['63']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '66', 'type': 'binary_operator', 'children': ['67', '72'], 'value': '*'},{'id': '67', 'type': 'attribute', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'PATH'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'paths'},{'id': '75', 'type': 'binary_operator', 'children': ['76', '81'], 'value': '*'},{'id': '76', 'type': 'attribute', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'LOCALE'},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'do_filter'},{'id': '87', 'type': 'boolean_operator', 'children': ['88', '93'], 'value': 'or'},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '92'], 'value': 'is'},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '92', 'type': 'None', 'children': []},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '97'], 'value': 'is'},{'id': '94', 'type': 'attribute', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'reverse_filter'},{'id': '97', 'type': 'None', 'children': []},{'id': '98', 'type': 'if_statement', 'children': ['99', '104']},{'id': '99', 'type': 'boolean_operator', 'children': ['100', '101'], 'value': 'or'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'do_filter'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '104', 'type': 'block', 'children': ['105', '136', '143', '191', '240']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'inp_options'},{'id': '108', 'type': '()', 'children': ['109']},{'id': '109', 'type': 'binary_operator', 'children': ['110', '125'], 'value': '|'},{'id': '110', 'type': 'binary_operator', 'children': ['111', '118'], 'value': '|'},{'id': '111', 'type': 'binary_operator', 'children': ['112', '117'], 'value': '*'},{'id': '112', 'type': 'attribute', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'FLOAT'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'is_float'},{'id': '118', 'type': 'binary_operator', 'children': ['119', '124'], 'value': '*'},{'id': '119', 'type': 'attribute', 'children': ['120', '123']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'SIGNED'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'signed'},{'id': '125', 'type': 'binary_operator', 'children': ['126', '131'], 'value': '*'},{'id': '126', 'type': 'attribute', 'children': ['127', '130']},{'id': '127', 'type': 'attribute', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'NOEXP'},{'id': '131', 'type': '()', 'children': ['132']},{'id': '132', 'type': 'not_operator', 'children': ['133']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'exp'},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '139', 'type': 'call', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'regex_chooser'},{'id': '141', 'type': 'argument_list', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'inp_options'},{'id': '143', 'type': 'if_statement', 'children': ['144', '149']},{'id': '144', 'type': 'comparison_operator', 'children': ['145', '148'], 'value': 'is'},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '148', 'type': 'None', 'children': []},{'id': '149', 'type': 'block', 'children': ['150', '174']},{'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': 'lows'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'highs'},{'id': '155', 'type': 'tuple', 'children': ['156', '165']},{'id': '156', 'type': 'list_comprehension', 'children': ['157', '160']},{'id': '157', 'type': 'subscript', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '159', 'type': 'integer', 'children': [], 'value': '0'},{'id': '160', 'type': 'for_in_clause', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '165', 'type': 'list_comprehension', 'children': ['166', '169']},{'id': '166', 'type': 'subscript', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '168', 'type': 'integer', 'children': [], 'value': '1'},{'id': '169', 'type': 'for_in_clause', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '174', 'type': 'expression_statement', 'children': ['175']},{'id': '175', 'type': 'assignment', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '177', 'type': 'list_comprehension', 'children': ['178', '179', '182']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '179', 'type': 'for_in_clause', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '182', 'type': 'if_clause', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'keep_entry_range'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187', '188', '189', '190']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'lows'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'highs'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '191', 'type': 'if_statement', 'children': ['192', '197']},{'id': '192', 'type': 'comparison_operator', 'children': ['193', '196'], 'value': 'is'},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'reverse_filter'},{'id': '196', 'type': 'None', 'children': []},{'id': '197', 'type': 'block', 'children': ['198', '222']},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '203']},{'id': '200', 'type': 'pattern_list', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'lows'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'highs'},{'id': '203', 'type': 'tuple', 'children': ['204', '213']},{'id': '204', 'type': 'list_comprehension', 'children': ['205', '208']},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '207', 'type': 'integer', 'children': [], 'value': '0'},{'id': '208', 'type': 'for_in_clause', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '210', 'type': 'attribute', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'reverse_filter'},{'id': '213', 'type': 'list_comprehension', 'children': ['214', '217']},{'id': '214', 'type': 'subscript', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '216', 'type': 'integer', 'children': [], 'value': '1'},{'id': '217', 'type': 'for_in_clause', 'children': ['218', '219']},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'reverse_filter'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '225', 'type': 'list_comprehension', 'children': ['226', '227', '230']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '227', 'type': 'for_in_clause', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '230', 'type': 'if_clause', 'children': ['231']},{'id': '231', 'type': 'not_operator', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'keep_entry_range'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236', '237', '238', '239']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'lows'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'highs'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '240', 'type': 'if_statement', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '244', 'type': 'block', 'children': ['245', '254']},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '248', 'type': 'call', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '250', 'type': 'argument_list', 'children': ['251']},{'id': '251', 'type': 'attribute', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'assignment', 'children': ['256', '257']},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '257', 'type': 'list_comprehension', 'children': ['258', '259', '262']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '259', 'type': 'for_in_clause', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '262', 'type': 'if_clause', 'children': ['263']},{'id': '263', 'type': 'call', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'keep_entry_value'},{'id': '265', 'type': 'argument_list', 'children': ['266', '267', '268', '269']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'exclude'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '270', 'type': 'for_statement', 'children': ['271', '272', '286']},{'id': '271', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '272', 'type': 'call', 'children': ['273', '276']},{'id': '273', 'type': 'attribute', 'children': ['274', '275']},{'id': '274', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'natsorted'},{'id': '276', 'type': 'argument_list', 'children': ['277', '278', '283']},{'id': '277', 'type': 'identifier', 'children': [], 'value': 'entries'},{'id': '278', 'type': 'keyword_argument', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '283', 'type': 'keyword_argument', 'children': ['284', '285']},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '286', 'type': 'block', 'children': ['287']},{'id': '287', 'type': 'expression_statement', 'children': ['288']},{'id': '288', 'type': 'call', 'children': ['289', '290']},{'id': '289', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '290', 'type': 'argument_list', 'children': ['291']},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'entry'}
def sort_and_print_entries(entries, args): is_float = args.number_type in ("float", "real", "f", "r") signed = args.signed or args.number_type in ("real", "r") alg = ( natsort.ns.FLOAT * is_float | natsort.ns.SIGNED * signed | natsort.ns.NOEXP * (not args.exp) | natsort.ns.PATH * args.paths | natsort.ns.LOCALE * args.locale ) do_filter = args.filter is not None or args.reverse_filter is not None if do_filter or args.exclude: inp_options = ( natsort.ns.FLOAT * is_float | natsort.ns.SIGNED * signed | natsort.ns.NOEXP * (not args.exp) ) regex = regex_chooser(inp_options) if args.filter is not None: lows, highs = ([f[0] for f in args.filter], [f[1] for f in args.filter]) entries = [ entry for entry in entries if keep_entry_range(entry, lows, highs, float, regex) ] if args.reverse_filter is not None: lows, highs = ( [f[0] for f in args.reverse_filter], [f[1] for f in args.reverse_filter], ) entries = [ entry for entry in entries if not keep_entry_range(entry, lows, highs, float, regex) ] if args.exclude: exclude = set(args.exclude) entries = [ entry for entry in entries if keep_entry_value(entry, exclude, float, regex) ] for entry in natsort.natsorted(entries, reverse=args.reverse, alg=alg): print(entry)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'natsort_key'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'string_func'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'bytes_func'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'num_func'},{'id': '9', 'type': 'block', 'children': ['10', '22']},{'id': '10', 'type': 'if_statement', 'children': ['11', '14']},{'id': '11', 'type': 'comparison_operator', 'children': ['12', '13'], 'value': 'is'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '22', 'type': 'try_statement', 'children': ['23', '29']},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'string_func'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '29', 'type': 'except_clause', 'children': ['30', '33']},{'id': '30', 'type': 'tuple', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'AttributeError'},{'id': '33', 'type': 'block', 'children': ['34', '48']},{'id': '34', 'type': 'if_statement', 'children': ['35', '42']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '40'], 'value': 'in'},{'id': '36', 'type': 'call', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '40', 'type': 'tuple', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'bytes'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'bytes_func'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '48', 'type': 'try_statement', 'children': ['49', '65']},{'id': '49', 'type': 'block', 'children': ['50']},{'id': '50', 'type': 'return_statement', 'children': ['51']},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '53', 'type': 'generator_expression', 'children': ['54', '62']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'natsort_key'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58', '59', '60', '61']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '58', 'type': 'None', 'children': []},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'string_func'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'bytes_func'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'num_func'},{'id': '62', 'type': 'for_in_clause', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '65', 'type': 'except_clause', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'call', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'num_func'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'val'}
def natsort_key(val, key, string_func, bytes_func, num_func): if key is not None: val = key(val) try: return string_func(val) except (TypeError, AttributeError): if type(val) in (bytes,): return bytes_func(val) try: return tuple( natsort_key(x, None, string_func, bytes_func, num_func) for x in val ) except TypeError: return num_func(val)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_number_factory'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'pre_sep'},{'id': '7', 'type': 'block', 'children': ['8', '25', '45']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'nan_replace'},{'id': '11', 'type': 'conditional_expression', 'children': ['12', '16', '21'], 'value': 'if'},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'string', 'children': [], 'value': '"+inf"'},{'id': '16', 'type': 'binary_operator', 'children': ['17', '18'], 'value': '&'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'NANLAST'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '23', 'type': 'argument_list', 'children': ['24']},{'id': '24', 'type': 'string', 'children': [], 'value': '"-inf"'},{'id': '25', 'type': 'function_definition', 'children': ['26', '27', '35']},{'id': '26', 'type': 'function_name', 'children': [], 'value': 'func'},{'id': '27', 'type': 'parameters', 'children': ['28', '29', '32']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '29', 'type': 'default_parameter', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_nan_replace'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'nan_replace'},{'id': '32', 'type': 'default_parameter', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': '_sep'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'expression_list', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': '_sep'},{'id': '39', 'type': 'conditional_expression', 'children': ['40', '41', '44'], 'value': 'if'},{'id': '40', 'type': 'identifier', 'children': [], 'value': '_nan_replace'},{'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': '!='},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '45', 'type': 'if_statement', 'children': ['46', '63', '76', '100', '116']},{'id': '46', 'type': 'boolean_operator', 'children': ['47', '58'], 'value': 'and'},{'id': '47', 'type': 'boolean_operator', 'children': ['48', '53'], 'value': 'and'},{'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '&'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'PATH'},{'id': '53', 'type': 'binary_operator', 'children': ['54', '55'], 'value': '&'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'UNGROUPLETTERS'},{'id': '58', 'type': 'binary_operator', 'children': ['59', '60'], 'value': '&'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'LOCALEALPHA'},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'return_statement', 'children': ['65']},{'id': '65', 'type': 'lambda', 'children': ['66', '68']},{'id': '66', 'type': 'lambda_parameters', 'children': ['67']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '68', 'type': 'tuple', 'children': ['69']},{'id': '69', 'type': 'tuple', 'children': ['70', '72']},{'id': '70', 'type': 'tuple', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'pre_sep'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '76', 'type': 'elif_clause', 'children': ['77', '88']},{'id': '77', 'type': 'boolean_operator', 'children': ['78', '83'], 'value': 'and'},{'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '&'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'UNGROUPLETTERS'},{'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '&'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'LOCALEALPHA'},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'return_statement', 'children': ['90']},{'id': '90', 'type': 'lambda', 'children': ['91', '93']},{'id': '91', 'type': 'lambda_parameters', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '93', 'type': 'tuple', 'children': ['94', '96']},{'id': '94', 'type': 'tuple', 'children': ['95']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'pre_sep'},{'id': '96', 'type': 'call', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '100', 'type': 'elif_clause', 'children': ['101', '106']},{'id': '101', 'type': 'binary_operator', 'children': ['102', '103'], 'value': '&'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'PATH'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'return_statement', 'children': ['108']},{'id': '108', 'type': 'lambda', 'children': ['109', '111']},{'id': '109', 'type': 'lambda_parameters', 'children': ['110']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '111', 'type': 'tuple', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'func'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '116', 'type': 'else_clause', 'children': ['117']},{'id': '117', 'type': 'block', 'children': ['118']},{'id': '118', 'type': 'return_statement', 'children': ['119']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'func'}
def parse_number_factory(alg, sep, pre_sep): nan_replace = float("+inf") if alg & ns.NANLAST else float("-inf") def func(val, _nan_replace=nan_replace, _sep=sep): return _sep, _nan_replace if val != val else val if alg & ns.PATH and alg & ns.UNGROUPLETTERS and alg & ns.LOCALEALPHA: return lambda x: (((pre_sep,), func(x)),) elif alg & ns.UNGROUPLETTERS and alg & ns.LOCALEALPHA: return lambda x: ((pre_sep,), func(x)) elif alg & ns.PATH: return lambda x: (func(x),) else: return func
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'natsort_keygen'},{'id': '3', 'type': 'parameters', 'children': ['4', '7']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '12', 'type': 'block', 'children': ['13', '43', '64', '151', '160', '169', '178', '189', '205', '221', '230', '241']},{'id': '13', 'type': 'try_statement', 'children': ['14', '21']},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'binary_operator', 'children': ['17', '20'], 'value': '|'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '21', 'type': 'except_clause', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '23', 'type': 'block', 'children': ['24', '28']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '27', 'type': 'string', 'children': [], 'value': '"natsort_keygen: \'alg\' argument must be from the enum \'ns\'"'},{'id': '28', 'type': 'raise_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '+'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'msg'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': '", got {}"'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'py23_str'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '43', 'type': 'if_statement', 'children': ['44', '59']},{'id': '44', 'type': 'boolean_operator', 'children': ['45', '50'], 'value': 'and'},{'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '&'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'LOCALEALPHA'},{'id': '50', 'type': 'call', 'children': ['51', '58']},{'id': '51', 'type': 'attribute', 'children': ['52', '57']},{'id': '52', 'type': 'attribute', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'dumb_sort'},{'id': '58', 'type': 'argument_list', 'children': []},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'augmented_assignment', 'children': ['62', '63'], 'value': '|='},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'NS_DUMB'},{'id': '64', 'type': 'if_statement', 'children': ['65', '70', '110']},{'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '&'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'NUMAFTER'},{'id': '70', 'type': 'block', 'children': ['71', '100']},{'id': '71', 'type': 'if_statement', 'children': ['72', '77', '88']},{'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '&'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'LOCALEALPHA'},{'id': '77', 'type': 'block', 'children': ['78']},{'id': '78', 'type': 'expression_statement', 'children': ['79']},{'id': '79', 'type': 'assignment', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '81', 'type': 'attribute', 'children': ['82', '87']},{'id': '82', 'type': 'attribute', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'null_string_locale_max'},{'id': '88', 'type': 'else_clause', 'children': ['89']},{'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': 'sep'},{'id': '93', 'type': 'attribute', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'null_string_max'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'pre_sep'},{'id': '103', 'type': 'attribute', 'children': ['104', '109']},{'id': '104', 'type': 'attribute', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'null_string_max'},{'id': '110', 'type': 'else_clause', 'children': ['111']},{'id': '111', 'type': 'block', 'children': ['112', '141']},{'id': '112', 'type': 'if_statement', 'children': ['113', '118', '129']},{'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '&'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'LOCALEALPHA'},{'id': '118', 'type': 'block', 'children': ['119']},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '122', 'type': 'attribute', 'children': ['123', '128']},{'id': '123', 'type': 'attribute', 'children': ['124', '127']},{'id': '124', 'type': 'attribute', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'null_string_locale'},{'id': '129', 'type': 'else_clause', 'children': ['130']},{'id': '130', 'type': 'block', 'children': ['131']},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '134', 'type': 'attribute', 'children': ['135', '140']},{'id': '135', 'type': 'attribute', 'children': ['136', '139']},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'null_string'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'pre_sep'},{'id': '144', 'type': 'attribute', 'children': ['145', '150']},{'id': '145', 'type': 'attribute', 'children': ['146', '149']},{'id': '146', 'type': 'attribute', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'natsort'},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'compat'},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'locale'},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'null_string'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'regex_chooser'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'input_transform'},{'id': '163', 'type': 'call', 'children': ['164', '167']},{'id': '164', 'type': 'attribute', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'input_string_transform_factory'},{'id': '167', 'type': 'argument_list', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'assignment', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'component_transform'},{'id': '172', 'type': 'call', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'string_component_transform_factory'},{'id': '176', 'type': 'argument_list', 'children': ['177']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '178', 'type': 'expression_statement', 'children': ['179']},{'id': '179', 'type': 'assignment', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'final_transform'},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'final_data_transform_factory'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187', '188']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'pre_sep'},{'id': '189', 'type': 'expression_statement', 'children': ['190']},{'id': '190', 'type': 'assignment', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'string_func'},{'id': '192', 'type': 'call', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'parse_string_factory'},{'id': '196', 'type': 'argument_list', 'children': ['197', '198', '199', '202', '203', '204']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'regex'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'input_transform'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'component_transform'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'final_transform'},{'id': '205', 'type': 'if_statement', 'children': ['206', '211']},{'id': '206', 'type': 'binary_operator', 'children': ['207', '208'], 'value': '&'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '208', 'type': 'attribute', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'PATH'},{'id': '211', 'type': 'block', 'children': ['212']},{'id': '212', 'type': 'expression_statement', 'children': ['213']},{'id': '213', 'type': 'assignment', 'children': ['214', '215']},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'string_func'},{'id': '215', 'type': 'call', 'children': ['216', '219']},{'id': '216', 'type': 'attribute', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'parse_path_factory'},{'id': '219', 'type': 'argument_list', 'children': ['220']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'string_func'},{'id': '221', 'type': 'expression_statement', 'children': ['222']},{'id': '222', 'type': 'assignment', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'bytes_func'},{'id': '224', 'type': 'call', 'children': ['225', '228']},{'id': '225', 'type': 'attribute', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'parse_bytes_factory'},{'id': '228', 'type': 'argument_list', 'children': ['229']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '230', 'type': 'expression_statement', 'children': ['231']},{'id': '231', 'type': 'assignment', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'num_func'},{'id': '233', 'type': 'call', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'parse_number_factory'},{'id': '237', 'type': 'argument_list', 'children': ['238', '239', '240']},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'sep'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'pre_sep'},{'id': '241', 'type': 'return_statement', 'children': ['242']},{'id': '242', 'type': 'call', 'children': ['243', '244']},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'partial'},{'id': '244', 'type': 'argument_list', 'children': ['245', '248', '251', '254', '257']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'utils'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'natsort_key'},{'id': '248', 'type': 'keyword_argument', 'children': ['249', '250']},{'id': '249', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '251', 'type': 'keyword_argument', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'string_func'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'string_func'},{'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'bytes_func'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'bytes_func'},{'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'num_func'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'num_func'}
def natsort_keygen(key=None, alg=ns.DEFAULT): try: ns.DEFAULT | alg except TypeError: msg = "natsort_keygen: 'alg' argument must be from the enum 'ns'" raise ValueError(msg + ", got {}".format(py23_str(alg))) if alg & ns.LOCALEALPHA and natsort.compat.locale.dumb_sort(): alg |= NS_DUMB if alg & ns.NUMAFTER: if alg & ns.LOCALEALPHA: sep = natsort.compat.locale.null_string_locale_max else: sep = natsort.compat.locale.null_string_max pre_sep = natsort.compat.locale.null_string_max else: if alg & ns.LOCALEALPHA: sep = natsort.compat.locale.null_string_locale else: sep = natsort.compat.locale.null_string pre_sep = natsort.compat.locale.null_string regex = utils.regex_chooser(alg) input_transform = utils.input_string_transform_factory(alg) component_transform = utils.string_component_transform_factory(alg) final_transform = utils.final_data_transform_factory(alg, sep, pre_sep) string_func = utils.parse_string_factory( alg, sep, regex.split, input_transform, component_transform, final_transform ) if alg & ns.PATH: string_func = utils.parse_path_factory(string_func) bytes_func = utils.parse_bytes_factory(alg) num_func = utils.parse_number_factory(alg, sep, pre_sep) return partial( utils.natsort_key, key=key, string_func=string_func, bytes_func=bytes_func, num_func=num_func, )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'natsorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '16', 'type': 'block', 'children': ['17', '25']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'natsort_keygen'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '25', 'type': 'return_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '28', 'type': 'argument_list', 'children': ['29', '30', '33']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '30', 'type': 'keyword_argument', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'}
def natsorted(seq, key=None, reverse=False, alg=ns.DEFAULT): key = natsort_keygen(key, alg) return sorted(seq, reverse=reverse, key=key)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'humansorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'natsorted'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23', '24']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '|'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'LOCALE'}
def humansorted(seq, key=None, reverse=False, alg=ns.DEFAULT): return natsorted(seq, key, reverse, alg | ns.LOCALE)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'realsorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'return_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'natsorted'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22', '23', '24']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '|'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'REAL'}
def realsorted(seq, key=None, reverse=False, alg=ns.DEFAULT): return natsorted(seq, key, reverse, alg | ns.REAL)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'index_natsorted'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '10', 'type': 'False', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'ns'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'DEFAULT'},{'id': '16', 'type': 'block', 'children': ['17', '47', '62', '78']},{'id': '17', 'type': 'if_statement', 'children': ['18', '21', '29']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'newkey'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'integer', 'children': [], 'value': '1'},{'id': '29', 'type': 'else_clause', 'children': ['30']},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'function_definition', 'children': ['32', '33', '35']},{'id': '32', 'type': 'function_name', 'children': [], 'value': 'newkey'},{'id': '33', 'type': 'parameters', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'call', 'children': ['41', '45']},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'itemgetter'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'integer', 'children': [], 'value': '1'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'index_seq_pair'},{'id': '50', 'type': 'list_comprehension', 'children': ['51', '54']},{'id': '51', 'type': 'list', 'children': ['52', '53'], 'value': '[x, y]'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '54', 'type': 'for_in_clause', 'children': ['55', '58']},{'id': '55', 'type': 'pattern_list', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'index_seq_pair'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '67', 'type': 'argument_list', 'children': ['68', '71']},{'id': '68', 'type': 'keyword_argument', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'natsort_keygen'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'newkey'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'alg'},{'id': '78', 'type': 'return_statement', 'children': ['79']},{'id': '79', 'type': 'list_comprehension', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '81', 'type': 'for_in_clause', 'children': ['82', '85']},{'id': '82', 'type': 'pattern_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '84', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'index_seq_pair'}
def index_natsorted(seq, key=None, reverse=False, alg=ns.DEFAULT): if key is None: newkey = itemgetter(1) else: def newkey(x): return key(itemgetter(1)(x)) index_seq_pair = [[x, y] for x, y in enumerate(seq)] index_seq_pair.sort(reverse=reverse, key=natsort_keygen(newkey, alg)) return [x for x, _ in index_seq_pair]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_by_index'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '8', 'type': 'False', 'children': []},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'return_statement', 'children': ['11']},{'id': '11', 'type': 'conditional_expression', 'children': ['12', '19', '20'], 'value': 'if'},{'id': '12', 'type': 'generator_expression', 'children': ['13', '16']},{'id': '13', 'type': 'subscript', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '16', 'type': 'for_in_clause', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '20', 'type': 'list_comprehension', 'children': ['21', '24']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'seq'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '24', 'type': 'for_in_clause', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'index'}
def order_by_index(seq, index, iter=False): return (seq[i] for i in index) if iter else [seq[i] for i in index]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_records'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'collection_name'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '8', 'type': 'dictionary', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort_direction'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '17', 'type': 'integer', 'children': [], 'value': '0'},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '36', '52', '61', '75']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '25', 'type': 'call', 'children': ['26', '34']},{'id': '26', 'type': 'attribute', 'children': ['27', '33']},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_get_collection'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'collection_name'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'find'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '36', 'type': 'if_statement', 'children': ['37', '40']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': '_apply_sort'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50', '51']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort_direction'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'skip'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '61', 'type': 'if_statement', 'children': ['62', '65']},{'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '64', 'type': 'None', 'children': []},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'expression_statement', 'children': ['67']},{'id': '67', 'type': 'assignment', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'MongoDbCursor'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'cursor'}
def find_records(self, collection_name, query={}, sort_by=None, sort_direction=None, start=0, limit=None): cursor = self._get_collection(collection_name).find(query) if sort_by is not None: cursor = self._apply_sort(cursor, sort_by, sort_direction) cursor = cursor.skip(start) if limit is not None: cursor = cursor.limit(limit) return MongoDbCursor(cursor)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_apply_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'sort_direction'},{'id': '7', 'type': 'block', 'children': ['8', '35']},{'id': '8', 'type': 'if_statement', 'children': ['9', '20', '27']},{'id': '9', 'type': 'boolean_operator', 'children': ['10', '13'], 'value': 'and'},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'is'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sort_direction'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '19'], 'value': '=='},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'sort_direction'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'string', 'children': [], 'value': '"desc"'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'pymongo'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'DESCENDING'},{'id': '27', 'type': 'else_clause', 'children': ['28']},{'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': 'sort'},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'pymongo'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'ASCENDING'},{'id': '35', 'type': 'return_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cursor'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort'}
def _apply_sort(cursor, sort_by, sort_direction): if sort_direction is not None and sort_direction.lower() == "desc": sort = pymongo.DESCENDING else: sort = pymongo.ASCENDING return cursor.sort(sort_by, sort)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_runs'},{'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': 'sort_by'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_direction'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '13', 'type': 'integer', 'children': [], 'value': '0'},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '19', 'type': 'dictionary', 'children': ['20', '23']},{'id': '20', 'type': 'pair', 'children': ['21', '22']},{'id': '21', 'type': 'string', 'children': [], 'value': '"type"'},{'id': '22', 'type': 'string', 'children': [], 'value': '"and"'},{'id': '23', 'type': 'pair', 'children': ['24', '25']},{'id': '24', 'type': 'string', 'children': [], 'value': '"filters"'},{'id': '25', 'type': 'list', 'children': [], 'value': '[]'},{'id': '26', 'type': 'block', 'children': ['27', '38', '74', '81']},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'all_run_ids'},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'listdir'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'directory'},{'id': '38', 'type': 'function_definition', 'children': ['39', '40', '41']},{'id': '39', 'type': 'function_name', 'children': [], 'value': 'run_iterator'},{'id': '40', 'type': 'parameters', 'children': []},{'id': '41', 'type': 'block', 'children': ['42', '50']},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'blacklist'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'list', 'children': ['49'], 'value': '["_sources"]'},{'id': '49', 'type': 'string', 'children': [], 'value': '"_sources"'},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'all_run_ids'},{'id': '53', 'type': 'block', 'children': ['54', '60']},{'id': '54', 'type': 'if_statement', 'children': ['55', '58']},{'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'in'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'blacklist'},{'id': '58', 'type': 'block', 'children': ['59']},{'id': '59', 'type': 'continue_statement', 'children': []},{'id': '60', 'type': 'try_statement', 'children': ['61', '70']},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'yield', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '70', 'type': 'except_clause', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'FileNotFoundError'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'pass_statement', 'children': []},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'all_run_ids'},{'id': '81', 'type': 'return_statement', 'children': ['82']},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'FileStoreCursor'},{'id': '84', 'type': 'argument_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '86', 'type': 'call', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'run_iterator'},{'id': '88', 'type': 'argument_list', 'children': []}
def get_runs(self, sort_by=None, sort_direction=None, start=0, limit=None, query={"type": "and", "filters": []}): all_run_ids = os.listdir(self.directory) def run_iterator(): blacklist = set(["_sources"]) for id in all_run_ids: if id in blacklist: continue try: yield self.get(id) except FileNotFoundError: pass count = len(all_run_ids) return FileStoreCursor(count, run_iterator())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_runs'},{'id': '3', 'type': 'parameters', 'children': []},{'id': '4', 'type': 'block', 'children': ['5', '13', '21', '29', '38', '47', '58', '69', '75', '106', '133', '141', '149']},{'id': '5', 'type': 'expression_statement', 'children': ['6']},{'id': '6', 'type': 'assignment', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '8', 'type': 'subscript', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'current_app'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'config'},{'id': '12', 'type': 'string', 'children': [], 'value': '"data"'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'draw'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'parse_int_arg'},{'id': '18', 'type': 'argument_list', 'children': ['19', '20']},{'id': '19', 'type': 'string', 'children': [], 'value': '"draw"'},{'id': '20', 'type': 'integer', 'children': [], 'value': '1'},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'parse_int_arg'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': '"start"'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'parse_int_arg'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'string', 'children': [], 'value': '"length"'},{'id': '36', 'type': 'unary_operator', 'children': ['37'], 'value': '-'},{'id': '37', 'type': 'integer', 'children': [], 'value': '1'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '41', 'type': 'conditional_expression', 'children': ['42', '43', '46'], 'value': 'if'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': '>='},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'None', 'children': []},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'order_column'},{'id': '50', 'type': 'call', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'string', 'children': [], 'value': '"order[0][column]"'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'order_dir'},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'string', 'children': [], 'value': '"order[0][dir]"'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'parse_query_filter'},{'id': '74', 'type': 'argument_list', 'children': []},{'id': '75', 'type': 'if_statement', 'children': ['76', '79']},{'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'is'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'order_column'},{'id': '78', 'type': 'None', 'children': []},{'id': '79', 'type': 'block', 'children': ['80', '97']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83', '84']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'order_column'},{'id': '83', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '84', 'type': 'call', 'children': ['85', '90']},{'id': '85', 'type': 'attribute', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'binary_operator', 'children': ['92', '93'], 'value': '%'},{'id': '92', 'type': 'string', 'children': [], 'value': '"columns[%d][name]"'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '95', 'type': 'argument_list', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'order_column'},{'id': '97', 'type': 'if_statement', 'children': ['98', '101']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': '=='},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'order_column'},{'id': '100', 'type': 'string', 'children': [], 'value': '"hostname"'},{'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': 'order_column'},{'id': '105', 'type': 'string', 'children': [], 'value': '"host.hostname"'},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'runs'},{'id': '109', 'type': 'call', 'children': ['110', '117']},{'id': '110', 'type': 'attribute', 'children': ['111', '116']},{'id': '111', 'type': 'call', 'children': ['112', '115']},{'id': '112', 'type': 'attribute', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'get_run_dao'},{'id': '115', 'type': 'argument_list', 'children': []},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'get_runs'},{'id': '117', 'type': 'argument_list', 'children': ['118', '121', '124', '127', '130']},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'start'},{'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'limit'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'length'},{'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'order_column'},{'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'sort_direction'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'order_dir'},{'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'assignment', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'records_total'},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'runs'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '140', 'type': 'argument_list', 'children': []},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'records_filtered'},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'runs'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'count'},{'id': '148', 'type': 'argument_list', 'children': []},{'id': '149', 'type': 'return_statement', 'children': ['150']},{'id': '150', 'type': 'call', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'Response'},{'id': '152', 'type': 'argument_list', 'children': ['153', '169']},{'id': '153', 'type': 'call', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'render_template'},{'id': '155', 'type': 'argument_list', 'children': ['156', '157', '160', '163', '166']},{'id': '156', 'type': 'string', 'children': [], 'value': '"api/runs.js"'},{'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'runs'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'runs'},{'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'draw'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'draw'},{'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'recordsTotal'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'records_total'},{'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'recordsFiltered'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'records_filtered'},{'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'mimetype'},{'id': '171', 'type': 'string', 'children': [], 'value': '"application/json"'}
def get_runs(): data = current_app.config["data"] draw = parse_int_arg("draw", 1) start = parse_int_arg("start", 0) length = parse_int_arg("length", -1) length = length if length >= 0 else None order_column = request.args.get("order[0][column]") order_dir = request.args.get("order[0][dir]") query = parse_query_filter() if order_column is not None: order_column = \ request.args.get("columns[%d][name]" % int(order_column)) if order_column == "hostname": order_column = "host.hostname" runs = data.get_run_dao().get_runs( start=start, limit=length, sort_by=order_column, sort_direction=order_dir, query=query) records_total = runs.count() records_filtered = runs.count() return Response(render_template( "api/runs.js", runs=runs, draw=draw, recordsTotal=records_total, recordsFiltered=records_filtered), mimetype="application/json")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate_querystring'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '5', 'type': 'block', 'children': ['6', '12', '16', '92']},{'id': '6', 'type': 'if_statement', 'children': ['7', '9']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '9', 'type': 'block', 'children': ['10']},{'id': '10', 'type': 'return_statement', 'children': ['11']},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '15', 'type': 'list', 'children': [], 'value': '[]'},{'id': '16', 'type': 'for_statement', 'children': ['17', '20', '28']},{'id': '17', 'type': 'pattern_list', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'block', 'children': ['29']},{'id': '29', 'type': 'if_statement', 'children': ['30', '36', '50']},{'id': '30', 'type': 'not_operator', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '33', 'type': 'argument_list', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '36', 'type': 'block', 'children': ['37']},{'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': 'parts'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'dictionary', 'children': ['47']},{'id': '47', 'type': 'pair', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '50', 'type': 'else_clause', 'children': ['51']},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'for_statement', 'children': ['53', '56', '64']},{'id': '53', 'type': 'pattern_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sub_value'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '63', 'type': 'argument_list', 'children': []},{'id': '64', 'type': 'block', 'children': ['65', '79']},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'composed'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'string', 'children': [], 'value': "'{param}[{key}]'"},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '72', 'type': 'argument_list', 'children': ['73', '76']},{'id': '73', 'type': 'keyword_argument', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'param'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '84']},{'id': '81', 'type': 'attribute', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'dictionary', 'children': ['89']},{'id': '89', 'type': 'pair', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'composed'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'sub_value'},{'id': '92', 'type': 'if_statement', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'parts'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'return_statement', 'children': ['96']},{'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': 'identifier', 'children': [], 'value': 'parts'}
def generate_querystring(params): if not params: return None parts = [] for param, value in sorted(params.items()): if not isinstance(value, dict): parts.append(urlencode({param: value})) else: for key, sub_value in sorted(value.items()): composed = '{param}[{key}]'.format(param=param, key=key) parts.append(urlencode({composed: sub_value})) if parts: return '&'.join(parts)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_catalog'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'catalog'},{'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '7', 'type': 'block', 'children': ['8', '18', '28', '38', '48', '54', '61', '70', '79', '92', '101', '111']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'bright_limit'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'string', 'children': [], 'value': "'bright_limit'"},{'id': '17', 'type': 'float', 'children': [], 'value': '1.00'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'max_bright'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': "'max_bright'"},{'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': 'min_bright'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'min_bright'"},{'id': '37', 'type': 'integer', 'children': [], 'value': '20'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'colname'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'colname'"},{'id': '47', 'type': 'string', 'children': [], 'value': "'vegamag'"},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'assignment', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'phot_column'},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'catalog'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'colname'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'num_sources'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'phot_column'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sort_indx'},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'phot_column'},{'id': '70', 'type': 'if_statement', 'children': ['71', '74']},{'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'is'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'max_bright'},{'id': '73', 'type': 'None', 'children': []},{'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': 'max_bright'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'num_sources'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'limit_num'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '84', 'type': 'argument_list', 'children': ['85', '91']},{'id': '85', 'type': 'call', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '87', 'type': 'argument_list', 'children': ['88']},{'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '*'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'num_sources'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'bright_limit'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'min_bright'},{'id': '92', 'type': 'expression_statement', 'children': ['93']},{'id': '93', 'type': 'assignment', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'limit_num'},{'id': '95', 'type': 'call', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '97', 'type': 'argument_list', 'children': ['98', '99', '100']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'max_bright'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'limit_num'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'num_sources'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'new_catalog'},{'id': '104', 'type': 'subscript', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'catalog'},{'id': '106', 'type': 'subscript', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'sort_indx'},{'id': '108', 'type': 'slice', 'children': ['109', '110']},{'id': '109', 'type': 'colon', 'children': []},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'limit_num'},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'new_catalog'}
def filter_catalog(catalog, **kwargs): bright_limit = kwargs.get('bright_limit', 1.00) max_bright = kwargs.get('max_bright', None) min_bright = kwargs.get('min_bright', 20) colname = kwargs.get('colname', 'vegamag') phot_column = catalog[colname] num_sources = len(phot_column) sort_indx = np.argsort(phot_column) if max_bright is None: max_bright = num_sources limit_num = max(int(num_sources * bright_limit), min_bright) limit_num = min(max_bright, limit_num, num_sources) new_catalog = catalog[sort_indx[:limit_num]] return new_catalog
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_timeseries'},{'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': 'ascending'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '17', '21', '36', '54', '60']},{'id': '9', 'type': 'if_statement', 'children': ['10', '15']},{'id': '10', 'type': 'boolean_operator', 'children': ['11', '12'], 'value': 'and'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_sorted'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'return_statement', 'children': []},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '20', 'type': 'integer', 'children': [], 'value': '1'},{'id': '21', 'type': 'if_statement', 'children': ['22', '24']},{'id': '22', 'type': 'not_operator', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '24', 'type': 'block', 'children': ['25', '30']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '28', 'type': 'unary_operator', 'children': ['29'], 'value': '-'},{'id': '29', 'type': 'integer', 'children': [], 'value': '1'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': '_predefinedSorted'},{'id': '35', 'type': 'False', 'children': []},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '43']},{'id': '38', 'type': 'attribute', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': '_timeseriesData'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '46', 'type': 'lambda', 'children': ['47', '49']},{'id': '47', 'type': 'lambda_parameters', 'children': ['48']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '49', 'type': 'binary_operator', 'children': ['50', '51'], 'value': '*'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '51', 'type': 'subscript', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '53', 'type': 'integer', 'children': [], 'value': '0'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': '_sorted'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}
def sort_timeseries(self, ascending=True): if ascending and self._sorted: return sortorder = 1 if not ascending: sortorder = -1 self._predefinedSorted = False self._timeseriesData.sort(key=lambda i: sortorder * i[0]) self._sorted = ascending return self
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_timeseries'},{'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': 'ascending'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '13', '22', '41', '50', '62', '68']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '12', 'type': 'integer', 'children': [], 'value': '1'},{'id': '13', 'type': 'if_statement', 'children': ['14', '16']},{'id': '14', 'type': 'not_operator', 'children': ['15']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '20', 'type': 'unary_operator', 'children': ['21'], 'value': '-'},{'id': '21', 'type': 'integer', 'children': [], 'value': '1'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '27', 'type': 'argument_list', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_timeseriesData'},{'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'lambda', 'children': ['34', '36']},{'id': '34', 'type': 'lambda_parameters', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '36', 'type': 'binary_operator', 'children': ['37', '38'], 'value': '*'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sortorder'},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'newTS'},{'id': '44', 'type': 'call', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'TimeSeries'},{'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': '_normalized'},{'id': '50', 'type': 'for_statement', 'children': ['51', '52', '53']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'entry'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '53', 'type': 'block', 'children': ['54']},{'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': 'newTS'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'add_entry'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'list_splat', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'entry'},{'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': 'newTS'},{'id': '66', 'type': 'identifier', 'children': [], 'value': '_sorted'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ascending'},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'newTS'}
def sorted_timeseries(self, ascending=True): sortorder = 1 if not ascending: sortorder = -1 data = sorted(self._timeseriesData, key=lambda i: sortorder * i[0]) newTS = TimeSeries(self._normalized) for entry in data: newTS.add_entry(*entry) newTS._sorted = ascending return newTS
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_calculate_values_to_forecast'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'timeSeries'},{'id': '6', 'type': 'block', 'children': ['7', '15', '28', '41', '57', '70']},{'id': '7', 'type': 'if_statement', 'children': ['8', '13']},{'id': '8', 'type': 'comparison_operator', 'children': ['9', '12'], 'value': 'is'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': '_forecastUntil'},{'id': '12', 'type': 'None', 'children': []},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'return_statement', 'children': []},{'id': '15', 'type': 'if_statement', 'children': ['16', '22']},{'id': '16', 'type': 'not_operator', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'timeSeries'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'is_sorted'},{'id': '21', 'type': 'argument_list', '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': 'ValueError'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'string', 'children': [], 'value': '"timeSeries has to be sorted."'},{'id': '28', 'type': 'if_statement', 'children': ['29', '35']},{'id': '29', 'type': 'not_operator', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '34']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'timeSeries'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'is_normalized'},{'id': '34', 'type': 'argument_list', 'children': []},{'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': '"timeSeries has to be normalized."'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'timediff'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '51'], 'value': '-'},{'id': '45', 'type': 'subscript', 'children': ['46', '50']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'timeSeries'},{'id': '48', 'type': 'unary_operator', 'children': ['49'], 'value': '-'},{'id': '49', 'type': 'integer', 'children': [], 'value': '1'},{'id': '50', 'type': 'integer', 'children': [], 'value': '0'},{'id': '51', 'type': 'subscript', 'children': ['52', '56']},{'id': '52', 'type': 'subscript', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'timeSeries'},{'id': '54', 'type': 'unary_operator', 'children': ['55'], 'value': '-'},{'id': '55', 'type': 'integer', 'children': [], 'value': '2'},{'id': '56', 'type': 'integer', 'children': [], 'value': '0'},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'forecastSpan'},{'id': '60', 'type': 'binary_operator', 'children': ['61', '64'], 'value': '-'},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': '_forecastUntil'},{'id': '64', 'type': 'subscript', 'children': ['65', '69']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'timeSeries'},{'id': '67', 'type': 'unary_operator', 'children': ['68'], 'value': '-'},{'id': '68', 'type': 'integer', 'children': [], 'value': '1'},{'id': '69', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'set_parameter'},{'id': '75', 'type': 'argument_list', 'children': ['76', '77']},{'id': '76', 'type': 'string', 'children': [], 'value': '"valuesToForecast"'},{'id': '77', 'type': 'binary_operator', 'children': ['78', '84'], 'value': '+'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'binary_operator', 'children': ['82', '83'], 'value': '/'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'forecastSpan'},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'timediff'},{'id': '84', 'type': 'integer', 'children': [], 'value': '1'}
def _calculate_values_to_forecast(self, timeSeries): if self._forecastUntil is None: return if not timeSeries.is_sorted(): raise ValueError("timeSeries has to be sorted.") if not timeSeries.is_normalized(): raise ValueError("timeSeries has to be normalized.") timediff = timeSeries[-1][0] - timeSeries[-2][0] forecastSpan = self._forecastUntil - timeSeries[-1][0] self.set_parameter("valuesToForecast", int(forecastSpan / timediff) + 1)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_bucket'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'max_keys'},{'id': '11', 'type': 'None', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'block', 'children': ['16', '20', '34', '51', '65', '83', '107', '121', '130']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '19', 'type': 'list', 'children': [], 'value': '[]'},{'id': '20', 'type': 'if_statement', 'children': ['21', '24']},{'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '23', 'type': 'None', 'children': []},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'tuple', 'children': ['32', '33']},{'id': '32', 'type': 'string', 'children': [], 'value': '"marker"'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'marker'},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'max_keys'},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'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': 'args'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'tuple', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': '"max-keys"'},{'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '%'},{'id': '48', 'type': 'string', 'children': [], 'value': '"%d"'},{'id': '49', 'type': 'tuple', 'children': ['50']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'max_keys'},{'id': '51', 'type': 'if_statement', 'children': ['52', '55']},{'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'is'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '54', 'type': 'None', 'children': []},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'tuple', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': '"prefix"'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '65', 'type': 'if_statement', 'children': ['66', '67', '77']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'args'},{'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': 'object_name'},{'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '+'},{'id': '72', 'type': 'string', 'children': [], 'value': '"?"'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'urlencode'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '77', 'type': 'else_clause', 'children': ['78']},{'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': 'object_name'},{'id': '82', 'type': 'None', 'children': []},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'details'},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_details'},{'id': '90', 'type': 'argument_list', 'children': ['91', '94']},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'method'},{'id': '93', 'type': 'string', 'children': [], 'value': 'b"GET"'},{'id': '94', 'type': 'keyword_argument', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'url_context'},{'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': '_url_context'},{'id': '100', 'type': 'argument_list', 'children': ['101', '104']},{'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'object_name'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'object_name'},{'id': '107', 'type': 'expression_statement', 'children': ['108']},{'id': '108', 'type': 'assignment', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': '_submit'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': '_query_factory'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'details'},{'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': 'd'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'addCallback'},{'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': '_parse_get_bucket'},{'id': '130', 'type': 'return_statement', 'children': ['131']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'd'}
def get_bucket(self, bucket, marker=None, max_keys=None, prefix=None): args = [] if marker is not None: args.append(("marker", marker)) if max_keys is not None: args.append(("max-keys", "%d" % (max_keys,))) if prefix is not None: args.append(("prefix", prefix)) if args: object_name = "?" + urlencode(args) else: object_name = None details = self._details( method=b"GET", url_context=self._url_context(bucket=bucket, object_name=object_name), ) d = self._submit(self._query_factory(details)) d.addCallback(self._parse_get_bucket) return d
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'findunique'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'lst'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'return_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'list_comprehension', 'children': ['15', '22']},{'id': '15', 'type': 'subscript', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'lst'}
def findunique(lst, key): return sorted(set([item[key.lower()] for item in lst]))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_input_dataframe_by_entity'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tax_benefit_system'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'nb_persons'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'nb_groups'},{'id': '7', 'type': 'block', 'children': ['8', '14', '30', '39', '45', '65', '76', '98', '110', '122', '127', '172', '277']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'input_dataframe_by_entity'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '13', 'type': 'argument_list', 'children': []},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'person_entity'},{'id': '17', 'type': 'subscript', 'children': ['18', '29']},{'id': '18', 'type': 'list_comprehension', 'children': ['19', '20', '25']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '20', 'type': 'for_in_clause', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'tax_benefit_system'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'entities'},{'id': '25', 'type': 'if_clause', 'children': ['26']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'is_person'},{'id': '29', 'type': 'integer', 'children': [], 'value': '0'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'person_id'},{'id': '33', 'type': 'call', 'children': ['34', '37']},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'arange'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'nb_persons'},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'input_dataframe_by_entity'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '44', 'type': 'argument_list', 'children': []},{'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': 'input_dataframe_by_entity'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'person_entity'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'dictionary', 'children': ['58']},{'id': '58', 'type': 'pair', 'children': ['59', '64']},{'id': '59', 'type': 'binary_operator', 'children': ['60', '63'], 'value': '+'},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'person_entity'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '63', 'type': 'string', 'children': [], 'value': "'_id'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'person_id'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '74']},{'id': '67', 'type': 'attribute', 'children': ['68', '73']},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'input_dataframe_by_entity'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'person_entity'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'set_index'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'string', 'children': [], 'value': "'person_id'"},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'adults'},{'id': '79', 'type': 'binary_operator', 'children': ['80', '82'], 'value': '+'},{'id': '80', 'type': 'list', 'children': ['81'], 'value': '[0]'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'random'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sample'},{'id': '89', 'type': 'argument_list', 'children': ['90', '95']},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '92', 'type': 'argument_list', 'children': ['93', '94']},{'id': '93', 'type': 'integer', 'children': [], 'value': '1'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'nb_persons'},{'id': '95', 'type': 'binary_operator', 'children': ['96', '97'], 'value': '-'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'nb_groups'},{'id': '97', 'type': 'integer', 'children': [], 'value': '1'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'members_entity_id'},{'id': '101', 'type': 'call', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '105', 'type': 'argument_list', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'nb_persons'},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'members_legacy_role'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'nb_persons'},{'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'dtype'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '122', 'type': 'expression_statement', 'children': ['123']},{'id': '123', 'type': 'assignment', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'id_group'},{'id': '125', 'type': 'unary_operator', 'children': ['126'], 'value': '-'},{'id': '126', 'type': 'integer', 'children': [], 'value': '1'},{'id': '127', 'type': 'for_statement', 'children': ['128', '129', '133']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'id_person'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'nb_persons'},{'id': '133', 'type': 'block', 'children': ['134', '160', '166']},{'id': '134', 'type': 'if_statement', 'children': ['135', '138', '147']},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': 'in'},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'id_person'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'adults'},{'id': '138', 'type': 'block', 'children': ['139', '143']},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'augmented_assignment', 'children': ['141', '142'], 'value': '+='},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'id_group'},{'id': '142', 'type': 'integer', 'children': [], 'value': '1'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'legacy_role'},{'id': '146', 'type': 'integer', 'children': [], 'value': '0'},{'id': '147', 'type': 'else_clause', 'children': ['148']},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'legacy_role'},{'id': '152', 'type': 'conditional_expression', 'children': ['153', '154', '157'], 'value': 'if'},{'id': '153', 'type': 'integer', 'children': [], 'value': '2'},{'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': '=='},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'legacy_role'},{'id': '156', 'type': 'integer', 'children': [], 'value': '0'},{'id': '157', 'type': 'binary_operator', 'children': ['158', '159'], 'value': '+'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'legacy_role'},{'id': '159', 'type': 'integer', 'children': [], 'value': '1'},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'assignment', 'children': ['162', '165']},{'id': '162', 'type': 'subscript', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'members_legacy_role'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'id_person'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'legacy_role'},{'id': '166', 'type': 'expression_statement', 'children': ['167']},{'id': '167', 'type': 'assignment', 'children': ['168', '171']},{'id': '168', 'type': 'subscript', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'members_entity_id'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'id_person'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'id_group'},{'id': '172', 'type': 'for_statement', 'children': ['173', '174', '177']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'tax_benefit_system'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'entities'},{'id': '177', 'type': 'block', 'children': ['178', '184', '190', '198', '206', '214', '244', '263']},{'id': '178', 'type': 'if_statement', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'is_person'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'continue_statement', 'children': []},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '187', 'type': 'attribute', 'children': ['188', '189']},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'assignment', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'person_dataframe'},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'input_dataframe_by_entity'},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'person_entity'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '205']},{'id': '200', 'type': 'subscript', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'person_dataframe'},{'id': '202', 'type': 'binary_operator', 'children': ['203', '204'], 'value': '+'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '204', 'type': 'string', 'children': [], 'value': "'_id'"},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'members_entity_id'},{'id': '206', 'type': 'expression_statement', 'children': ['207']},{'id': '207', 'type': 'assignment', 'children': ['208', '213']},{'id': '208', 'type': 'subscript', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'person_dataframe'},{'id': '210', 'type': 'binary_operator', 'children': ['211', '212'], 'value': '+'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '212', 'type': 'string', 'children': [], 'value': "'_legacy_role'"},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'members_legacy_role'},{'id': '214', 'type': 'expression_statement', 'children': ['215']},{'id': '215', 'type': 'assignment', 'children': ['216', '221']},{'id': '216', 'type': 'subscript', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'person_dataframe'},{'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '+'},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '220', 'type': 'string', 'children': [], 'value': "'_role'"},{'id': '221', 'type': 'call', 'children': ['222', '225']},{'id': '222', 'type': 'attribute', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '225', 'type': 'argument_list', 'children': ['226', '229', '236']},{'id': '226', 'type': 'comparison_operator', 'children': ['227', '228'], 'value': '=='},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'members_legacy_role'},{'id': '228', 'type': 'integer', 'children': [], 'value': '0'},{'id': '229', 'type': 'attribute', 'children': ['230', '235']},{'id': '230', 'type': 'subscript', 'children': ['231', '234']},{'id': '231', 'type': 'attribute', 'children': ['232', '233']},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'flattened_roles'},{'id': '234', 'type': 'integer', 'children': [], 'value': '0'},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '236', 'type': 'attribute', 'children': ['237', '243']},{'id': '237', 'type': 'subscript', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'entity'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'flattened_roles'},{'id': '241', 'type': 'unary_operator', 'children': ['242'], 'value': '-'},{'id': '242', 'type': 'integer', 'children': [], 'value': '1'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '244', 'type': 'expression_statement', 'children': ['245']},{'id': '245', 'type': 'assignment', 'children': ['246', '249']},{'id': '246', 'type': 'subscript', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'input_dataframe_by_entity'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '249', 'type': 'call', 'children': ['250', '253']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '253', 'type': 'argument_list', 'children': ['254']},{'id': '254', 'type': 'dictionary', 'children': ['255']},{'id': '255', 'type': 'pair', 'children': ['256', '259']},{'id': '256', 'type': 'binary_operator', 'children': ['257', '258'], 'value': '+'},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '258', 'type': 'string', 'children': [], 'value': "'_id'"},{'id': '259', 'type': 'call', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '261', 'type': 'argument_list', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'nb_groups'},{'id': '263', 'type': 'expression_statement', 'children': ['264']},{'id': '264', 'type': 'call', 'children': ['265', '270']},{'id': '265', 'type': 'attribute', 'children': ['266', '269']},{'id': '266', 'type': 'subscript', 'children': ['267', '268']},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'input_dataframe_by_entity'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '269', 'type': 'identifier', 'children': [], 'value': 'set_index'},{'id': '270', 'type': 'argument_list', 'children': ['271', '274']},{'id': '271', 'type': 'binary_operator', 'children': ['272', '273'], 'value': '+'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '273', 'type': 'string', 'children': [], 'value': "'_id'"},{'id': '274', 'type': 'keyword_argument', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'inplace'},{'id': '276', 'type': 'True', 'children': []},{'id': '277', 'type': 'return_statement', 'children': ['278']},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'input_dataframe_by_entity'}
def make_input_dataframe_by_entity(tax_benefit_system, nb_persons, nb_groups): input_dataframe_by_entity = dict() person_entity = [entity for entity in tax_benefit_system.entities if entity.is_person][0] person_id = np.arange(nb_persons) input_dataframe_by_entity = dict() input_dataframe_by_entity[person_entity.key] = pd.DataFrame({ person_entity.key + '_id': person_id, }) input_dataframe_by_entity[person_entity.key].set_index('person_id') adults = [0] + sorted(random.sample(range(1, nb_persons), nb_groups - 1)) members_entity_id = np.empty(nb_persons, dtype = int) members_legacy_role = np.empty(nb_persons, dtype = int) id_group = -1 for id_person in range(nb_persons): if id_person in adults: id_group += 1 legacy_role = 0 else: legacy_role = 2 if legacy_role == 0 else legacy_role + 1 members_legacy_role[id_person] = legacy_role members_entity_id[id_person] = id_group for entity in tax_benefit_system.entities: if entity.is_person: continue key = entity.key person_dataframe = input_dataframe_by_entity[person_entity.key] person_dataframe[key + '_id'] = members_entity_id person_dataframe[key + '_legacy_role'] = members_legacy_role person_dataframe[key + '_role'] = np.where( members_legacy_role == 0, entity.flattened_roles[0].key, entity.flattened_roles[-1].key) input_dataframe_by_entity[key] = pd.DataFrame({ key + '_id': range(nb_groups) }) input_dataframe_by_entity[key].set_index(key + '_id', inplace = True) return input_dataframe_by_entity
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'multi_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'remotes'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '6', 'type': 'block', 'children': ['7', '13', '19', '74', '91', '97', '168']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'exploded_alpha'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'exploded_semver'},{'id': '16', 'type': 'call', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'if_statement', 'children': ['20', '23']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'in'},{'id': '21', 'type': 'string', 'children': [], 'value': "'alpha'"},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '23', 'type': 'block', 'children': ['24', '39']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'alpha_max_len'},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '29', 'type': 'generator_expression', 'children': ['30', '36']},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '35', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'remotes'},{'id': '39', 'type': 'for_statement', 'children': ['40', '41', '48']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '41', 'type': 'generator_expression', 'children': ['42', '45']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '44', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '45', 'type': 'for_in_clause', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'remotes'},{'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': 'exploded_alpha'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'binary_operator', 'children': ['56', '64'], 'value': '+'},{'id': '56', 'type': 'list_comprehension', 'children': ['57', '61']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'ord'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '61', 'type': 'for_in_clause', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '64', 'type': 'binary_operator', 'children': ['65', '67'], 'value': '*'},{'id': '65', 'type': 'list', 'children': ['66'], 'value': '[0]'},{'id': '66', 'type': 'integer', 'children': [], 'value': '0'},{'id': '67', 'type': '()', 'children': ['68']},{'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '-'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'alpha_max_len'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '74', 'type': 'if_statement', 'children': ['75', '78']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'in'},{'id': '76', 'type': 'string', 'children': [], 'value': "'semver'"},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sort'},{'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': 'exploded_semver'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'semvers'},{'id': '84', 'type': 'generator_expression', 'children': ['85', '88']},{'id': '85', 'type': 'subscript', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '87', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '88', 'type': 'for_in_clause', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'remotes'},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sort_mapping'},{'id': '94', 'type': 'call', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '96', 'type': 'argument_list', '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': 'remote'},{'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': 'remotes'},{'id': '105', 'type': 'block', 'children': ['106', '112', '159']},{'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': 'list'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'for_statement', 'children': ['113', '114', '115']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '115', 'type': 'block', 'children': ['116']},{'id': '116', 'type': 'if_statement', 'children': ['117', '120', '130', '145']},{'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': '=='},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '119', 'type': 'string', 'children': [], 'value': "'alpha'"},{'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': 'key'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '126', 'type': 'argument_list', 'children': ['127']},{'id': '127', 'type': 'subscript', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'exploded_alpha'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '130', 'type': 'elif_clause', 'children': ['131', '134']},{'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': '=='},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '133', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '134', 'type': 'block', 'children': ['135']},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'call', 'children': ['137', '140']},{'id': '137', 'type': 'attribute', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'unary_operator', 'children': ['142'], 'value': '-'},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'remote'},{'id': '144', 'type': 'string', 'children': [], 'value': "'date'"},{'id': '145', 'type': 'elif_clause', 'children': ['146', '149']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': '=='},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '148', 'type': 'string', 'children': [], 'value': "'semver'"},{'id': '149', 'type': 'block', 'children': ['150']},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'exploded_semver'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '159', 'type': 'expression_statement', 'children': ['160']},{'id': '160', 'type': 'assignment', 'children': ['161', '167']},{'id': '161', 'type': 'subscript', 'children': ['162', '163']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'sort_mapping'},{'id': '163', 'type': 'call', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'remote'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'key'},{'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': 'remotes'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'keyword_argument', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '176', 'type': 'lambda', 'children': ['177', '179']},{'id': '177', 'type': 'lambda_parameters', 'children': ['178']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '179', 'type': 'call', 'children': ['180', '183']},{'id': '180', 'type': 'attribute', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'sort_mapping'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'call', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'id'},{'id': '186', 'type': 'argument_list', 'children': ['187']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'k'}
def multi_sort(remotes, sort): exploded_alpha = list() exploded_semver = list() if 'alpha' in sort: alpha_max_len = max(len(r['name']) for r in remotes) for name in (r['name'] for r in remotes): exploded_alpha.append([ord(i) for i in name] + [0] * (alpha_max_len - len(name))) if 'semver' in sort: exploded_semver = semvers(r['name'] for r in remotes) sort_mapping = dict() for i, remote in enumerate(remotes): key = list() for sort_by in sort: if sort_by == 'alpha': key.extend(exploded_alpha[i]) elif sort_by == 'time': key.append(-remote['date']) elif sort_by == 'semver': key.extend(exploded_semver[i]) sort_mapping[id(remote)] = key remotes.sort(key=lambda k: sort_mapping.get(id(k)))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_params'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'ctx'},{'id': '6', 'type': 'block', 'children': ['7', '20']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '14']},{'id': '9', 'type': 'attribute', 'children': ['10', '13']},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '14', 'type': 'argument_list', 'children': ['15']},{'id': '15', 'type': 'keyword_argument', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'custom_sort'},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '29']},{'id': '22', 'type': 'attribute', 'children': ['23', '28']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'ClickGroup'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_params'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'ctx'}
def get_params(self, ctx): self.params.sort(key=self.custom_sort) return super(ClickGroup, self).get_params(ctx)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'configure_switch_entries'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'switch_ip'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'port_bindings'},{'id': '7', 'type': 'block', 'children': ['8', '13', '18', '22', '26', '34', '55', '68', '74', '80', '84', '88', '92', '294', '322', '333', '346', '353', '393', '403', '410']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'prev_vlan'},{'id': '11', 'type': 'unary_operator', 'children': ['12'], 'value': '-'},{'id': '12', 'type': 'integer', 'children': [], 'value': '1'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'prev_vni'},{'id': '16', 'type': 'unary_operator', 'children': ['17'], 'value': '-'},{'id': '17', 'type': 'integer', 'children': [], 'value': '1'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'prev_port'},{'id': '21', 'type': 'None', 'children': []},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'prev_native_vlan'},{'id': '25', 'type': 'integer', 'children': [], 'value': '0'},{'id': '26', 'type': 'expression_statement', 'children': ['27']},{'id': '27', 'type': 'assignment', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'starttime'},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'port_bindings'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'keyword_argument', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '42', 'type': 'lambda', 'children': ['43', '45']},{'id': '43', 'type': 'lambda_parameters', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '45', 'type': 'tuple', 'children': ['46', '49', '52']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'port_id'},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'vlan_id'},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'vni'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'driver'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'capture_and_print_timeshot'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64', '65']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'starttime'},{'id': '64', 'type': 'string', 'children': [], 'value': '"replay_t2_aft_sort"'},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'switch'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'switch_ip'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'vlans'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '73', 'type': 'argument_list', 'children': []},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'pvlans'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '79', 'type': 'argument_list', 'children': []},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'interface_count'},{'id': '83', 'type': 'integer', 'children': [], 'value': '0'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'duplicate_port'},{'id': '87', 'type': 'integer', 'children': [], 'value': '0'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'vlan_count'},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'for_statement', 'children': ['93', '94', '95']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'port_bindings'},{'id': '95', 'type': 'block', 'children': ['96', '105', '126']},{'id': '96', 'type': 'if_statement', 'children': ['97', '103']},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'nxos_db'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'is_reserved_binding'},{'id': '101', 'type': 'argument_list', 'children': ['102']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'continue_statement', 'children': []},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'assignment', 'children': ['107', '110']},{'id': '107', 'type': 'pattern_list', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'auto_create'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'auto_trunk'},{'id': '110', 'type': 'call', 'children': ['111', '114']},{'id': '111', 'type': 'attribute', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '113', 'type': 'identifier', 'children': [], 'value': '_gather_config_parms'},{'id': '114', 'type': 'argument_list', 'children': ['115', '123']},{'id': '115', 'type': 'call', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'nxos_db'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'is_provider_vlan'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'attribute', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'vlan_id'},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'vlan_id'},{'id': '126', 'type': 'if_statement', 'children': ['127', '132', '196']},{'id': '127', 'type': 'comparison_operator', 'children': ['128', '131'], 'value': '=='},{'id': '128', 'type': 'attribute', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'port_id'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'prev_port'},{'id': '132', 'type': 'block', 'children': ['133']},{'id': '133', 'type': 'if_statement', 'children': ['134', '145', '151']},{'id': '134', 'type': 'boolean_operator', 'children': ['135', '140'], 'value': 'and'},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '139'], 'value': '=='},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'vlan_id'},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'prev_vlan'},{'id': '140', 'type': 'comparison_operator', 'children': ['141', '144'], 'value': '=='},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'vni'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'prev_vni'},{'id': '145', 'type': 'block', 'children': ['146', '150']},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'augmented_assignment', 'children': ['148', '149'], 'value': '+='},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'duplicate_port'},{'id': '149', 'type': 'integer', 'children': [], 'value': '1'},{'id': '150', 'type': 'continue_statement', 'children': []},{'id': '151', 'type': 'else_clause', 'children': ['152']},{'id': '152', 'type': 'block', 'children': ['153', '157', '173', '185']},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'augmented_assignment', 'children': ['155', '156'], 'value': '+='},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'vlan_count'},{'id': '156', 'type': 'integer', 'children': [], 'value': '1'},{'id': '157', 'type': 'if_statement', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'auto_create'},{'id': '159', 'type': 'block', 'children': ['160']},{'id': '160', 'type': 'expression_statement', 'children': ['161']},{'id': '161', 'type': 'call', 'children': ['162', '165']},{'id': '162', 'type': 'attribute', 'children': ['163', '164']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'vlans'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '165', 'type': 'argument_list', 'children': ['166']},{'id': '166', 'type': 'tuple', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'vlan_id'},{'id': '170', 'type': 'attribute', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'vni'},{'id': '173', 'type': 'if_statement', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'auto_trunk'},{'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': 'pvlans'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '181', 'type': 'argument_list', 'children': ['182']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'vlan_id'},{'id': '185', 'type': 'if_statement', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'is_native'},{'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': 'prev_native_vlan'},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'vlan_id'},{'id': '196', 'type': 'else_clause', 'children': ['197']},{'id': '197', 'type': 'block', 'children': ['198', '218', '222', '226', '249', '265', '277', '283']},{'id': '198', 'type': 'if_statement', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'prev_port'},{'id': '200', 'type': 'block', 'children': ['201', '205']},{'id': '201', 'type': 'expression_statement', 'children': ['202']},{'id': '202', 'type': 'augmented_assignment', 'children': ['203', '204'], 'value': '+='},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'interface_count'},{'id': '204', 'type': 'integer', 'children': [], 'value': '1'},{'id': '205', 'type': 'expression_statement', 'children': ['206']},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '210', 'type': 'argument_list', 'children': ['211', '214', '215', '216', '217']},{'id': '211', 'type': 'concatenated_string', 'children': ['212', '213']},{'id': '212', 'type': 'string', 'children': [], 'value': '"Switch %s port %s replay summary: unique vlan "'},{'id': '213', 'type': 'string', 'children': [], 'value': '"count %d, duplicate port entries %d"'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'switch_ip'},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'prev_port'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'vlan_count'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'duplicate_port'},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'assignment', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'duplicate_port'},{'id': '221', 'type': 'integer', 'children': [], 'value': '0'},{'id': '222', 'type': 'expression_statement', 'children': ['223']},{'id': '223', 'type': 'assignment', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'vlan_count'},{'id': '225', 'type': 'integer', 'children': [], 'value': '0'},{'id': '226', 'type': 'if_statement', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'pvlans'},{'id': '228', 'type': 'block', 'children': ['229', '239', '245']},{'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': 'self'},{'id': '233', 'type': 'identifier', 'children': [], 'value': '_restore_port_binding'},{'id': '234', 'type': 'argument_list', 'children': ['235', '236', '237', '238']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'switch_ip'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'pvlans'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'prev_port'},{'id': '238', 'type': 'identifier', 'children': [], 'value': 'prev_native_vlan'},{'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': 'pvlans'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '244', 'type': 'argument_list', 'children': []},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'id': '246', 'type': 'assignment', 'children': ['247', '248']},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'prev_native_vlan'},{'id': '248', 'type': 'integer', 'children': [], 'value': '0'},{'id': '249', 'type': 'if_statement', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'auto_create'},{'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': 'vlans'},{'id': '256', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '257', 'type': 'argument_list', 'children': ['258']},{'id': '258', 'type': 'tuple', 'children': ['259', '262']},{'id': '259', 'type': 'attribute', 'children': ['260', '261']},{'id': '260', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '261', 'type': 'identifier', 'children': [], 'value': 'vlan_id'},{'id': '262', 'type': 'attribute', 'children': ['263', '264']},{'id': '263', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'vni'},{'id': '265', 'type': 'if_statement', 'children': ['266', '267']},{'id': '266', 'type': 'identifier', 'children': [], 'value': 'auto_trunk'},{'id': '267', 'type': 'block', 'children': ['268']},{'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': 'pvlans'},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '273', 'type': 'argument_list', 'children': ['274']},{'id': '274', 'type': 'attribute', 'children': ['275', '276']},{'id': '275', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '276', 'type': 'identifier', 'children': [], 'value': 'vlan_id'},{'id': '277', 'type': 'expression_statement', 'children': ['278']},{'id': '278', 'type': 'assignment', 'children': ['279', '280']},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'prev_port'},{'id': '280', 'type': 'attribute', 'children': ['281', '282']},{'id': '281', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '282', 'type': 'identifier', 'children': [], 'value': 'port_id'},{'id': '283', 'type': 'if_statement', 'children': ['284', '287']},{'id': '284', 'type': 'attribute', 'children': ['285', '286']},{'id': '285', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '286', 'type': 'identifier', 'children': [], 'value': 'is_native'},{'id': '287', 'type': 'block', 'children': ['288']},{'id': '288', 'type': 'expression_statement', 'children': ['289']},{'id': '289', 'type': 'assignment', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'prev_native_vlan'},{'id': '291', 'type': 'attribute', 'children': ['292', '293']},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '293', 'type': 'identifier', 'children': [], 'value': 'vlan_id'},{'id': '294', 'type': 'if_statement', 'children': ['295', '296']},{'id': '295', 'type': 'identifier', 'children': [], 'value': 'pvlans'},{'id': '296', 'type': 'block', 'children': ['297', '312']},{'id': '297', 'type': 'expression_statement', 'children': ['298']},{'id': '298', 'type': 'call', 'children': ['299', '302']},{'id': '299', 'type': 'attribute', 'children': ['300', '301']},{'id': '300', 'type': 'identifier', 'children': [], 'value': 'LOG'},{'id': '301', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '302', 'type': 'argument_list', 'children': ['303', '306', '307', '310', '311']},{'id': '303', 'type': 'concatenated_string', 'children': ['304', '305']},{'id': '304', 'type': 'string', 'children': [], 'value': '"Switch %s port %s replay summary: unique vlan "'},{'id': '305', 'type': 'string', 'children': [], 'value': '"count %d, duplicate port entries %d"'},{'id': '306', 'type': 'identifier', 'children': [], 'value': 'switch_ip'},{'id': '307', 'type': 'attribute', 'children': ['308', '309']},{'id': '308', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '309', 'type': 'identifier', 'children': [], 'value': 'port_id'},{'id': '310', 'type': 'identifier', 'children': [], 'value': 'vlan_count'},{'id': '311', 'type': 'identifier', 'children': [], 'value': 'duplicate_port'},{'id': '312', 'type': 'expression_statement', 'children': ['313']},{'id': '313', 'type': 'call', 'children': ['314', '317']},{'id': '314', 'type': 'attribute', 'children': ['315', '316']},{'id': '315', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '316', 'type': 'identifier', 'children': [], 'value': '_restore_port_binding'},{'id': '317', 'type': 'argument_list', 'children': ['318', '319', '320', '321']},{'id': '318', 'type': 'identifier', 'children': [], 'value': 'switch_ip'},{'id': '319', 'type': 'identifier', 'children': [], 'value': 'pvlans'},{'id': '320', 'type': 'identifier', 'children': [], 'value': 'prev_port'},{'id': '321', 'type': 'identifier', 'children': [], 'value': 'prev_native_vlan'},{'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': 'LOG'},{'id': '326', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '327', 'type': 'argument_list', 'children': ['328', '329', '332']},{'id': '328', 'type': 'string', 'children': [], 'value': '"Replayed total %d ports for Switch %s"'},{'id': '329', 'type': 'binary_operator', 'children': ['330', '331'], 'value': '+'},{'id': '330', 'type': 'identifier', 'children': [], 'value': 'interface_count'},{'id': '331', 'type': 'integer', 'children': [], 'value': '1'},{'id': '332', 'type': 'identifier', 'children': [], 'value': 'switch_ip'},{'id': '333', 'type': 'expression_statement', 'children': ['334']},{'id': '334', 'type': 'call', 'children': ['335', '340']},{'id': '335', 'type': 'attribute', 'children': ['336', '339']},{'id': '336', 'type': 'attribute', 'children': ['337', '338']},{'id': '337', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '338', 'type': 'identifier', 'children': [], 'value': 'driver'},{'id': '339', 'type': 'identifier', 'children': [], 'value': 'capture_and_print_timeshot'},{'id': '340', 'type': 'argument_list', 'children': ['341', '342', '343']},{'id': '341', 'type': 'identifier', 'children': [], 'value': 'starttime'},{'id': '342', 'type': 'string', 'children': [], 'value': '"replay_part_1"'},{'id': '343', 'type': 'keyword_argument', 'children': ['344', '345']},{'id': '344', 'type': 'identifier', 'children': [], 'value': 'switch'},{'id': '345', 'type': 'identifier', 'children': [], 'value': 'switch_ip'},{'id': '346', 'type': 'expression_statement', 'children': ['347']},{'id': '347', 'type': 'assignment', 'children': ['348', '349']},{'id': '348', 'type': 'identifier', 'children': [], 'value': 'vlans'},{'id': '349', 'type': 'call', 'children': ['350', '351']},{'id': '350', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '351', 'type': 'argument_list', 'children': ['352']},{'id': '352', 'type': 'identifier', 'children': [], 'value': 'vlans'},{'id': '353', 'type': 'if_statement', 'children': ['354', '355']},{'id': '354', 'type': 'identifier', 'children': [], 'value': 'vlans'},{'id': '355', 'type': 'block', 'children': ['356', '362', '370']},{'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': 'vlans'},{'id': '360', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '361', 'type': 'argument_list', 'children': []},{'id': '362', 'type': 'expression_statement', 'children': ['363']},{'id': '363', 'type': 'assignment', 'children': ['364', '367']},{'id': '364', 'type': 'pattern_list', 'children': ['365', '366']},{'id': '365', 'type': 'identifier', 'children': [], 'value': 'vlan'},{'id': '366', 'type': 'identifier', 'children': [], 'value': 'vni'},{'id': '367', 'type': 'subscript', 'children': ['368', '369']},{'id': '368', 'type': 'identifier', 'children': [], 'value': 'vlans'},{'id': '369', 'type': 'integer', 'children': [], 'value': '0'},{'id': '370', 'type': 'if_statement', 'children': ['371', '374', '383']},{'id': '371', 'type': 'comparison_operator', 'children': ['372', '373'], 'value': '=='},{'id': '372', 'type': 'identifier', 'children': [], 'value': 'vni'},{'id': '373', 'type': 'integer', 'children': [], 'value': '0'},{'id': '374', 'type': 'block', 'children': ['375']},{'id': '375', 'type': 'expression_statement', 'children': ['376']},{'id': '376', 'type': 'call', 'children': ['377', '380']},{'id': '377', 'type': 'attribute', 'children': ['378', '379']},{'id': '378', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '379', 'type': 'identifier', 'children': [], 'value': '_save_switch_vlan_range'},{'id': '380', 'type': 'argument_list', 'children': ['381', '382']},{'id': '381', 'type': 'identifier', 'children': [], 'value': 'switch_ip'},{'id': '382', 'type': 'identifier', 'children': [], 'value': 'vlans'},{'id': '383', 'type': 'else_clause', 'children': ['384']},{'id': '384', 'type': 'block', 'children': ['385']},{'id': '385', 'type': 'expression_statement', 'children': ['386']},{'id': '386', 'type': 'call', 'children': ['387', '390']},{'id': '387', 'type': 'attribute', 'children': ['388', '389']},{'id': '388', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '389', 'type': 'identifier', 'children': [], 'value': '_save_switch_vxlan_range'},{'id': '390', 'type': 'argument_list', 'children': ['391', '392']},{'id': '391', 'type': 'identifier', 'children': [], 'value': 'switch_ip'},{'id': '392', 'type': 'identifier', 'children': [], 'value': 'vlans'},{'id': '393', 'type': 'expression_statement', 'children': ['394']},{'id': '394', 'type': 'call', 'children': ['395', '398']},{'id': '395', 'type': 'attribute', 'children': ['396', '397']},{'id': '396', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '397', 'type': 'identifier', 'children': [], 'value': 'set_switch_ip_and_active_state'},{'id': '398', 'type': 'argument_list', 'children': ['399', '400']},{'id': '399', 'type': 'identifier', 'children': [], 'value': 'switch_ip'},{'id': '400', 'type': 'attribute', 'children': ['401', '402']},{'id': '401', 'type': 'identifier', 'children': [], 'value': 'const'},{'id': '402', 'type': 'identifier', 'children': [], 'value': 'SWITCH_RESTORE_S2'},{'id': '403', 'type': 'expression_statement', 'children': ['404']},{'id': '404', 'type': 'call', 'children': ['405', '408']},{'id': '405', 'type': 'attribute', 'children': ['406', '407']},{'id': '406', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '407', 'type': 'identifier', 'children': [], 'value': 'configure_next_batch_of_vlans'},{'id': '408', 'type': 'argument_list', 'children': ['409']},{'id': '409', 'type': 'identifier', 'children': [], 'value': 'switch_ip'},{'id': '410', 'type': 'expression_statement', 'children': ['411']},{'id': '411', 'type': 'call', 'children': ['412', '417']},{'id': '412', 'type': 'attribute', 'children': ['413', '416']},{'id': '413', 'type': 'attribute', 'children': ['414', '415']},{'id': '414', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '415', 'type': 'identifier', 'children': [], 'value': 'driver'},{'id': '416', 'type': 'identifier', 'children': [], 'value': 'capture_and_print_timeshot'},{'id': '417', 'type': 'argument_list', 'children': ['418', '419', '420']},{'id': '418', 'type': 'identifier', 'children': [], 'value': 'starttime'},{'id': '419', 'type': 'string', 'children': [], 'value': '"replay_part_2"'},{'id': '420', 'type': 'keyword_argument', 'children': ['421', '422']},{'id': '421', 'type': 'identifier', 'children': [], 'value': 'switch'},{'id': '422', 'type': 'identifier', 'children': [], 'value': 'switch_ip'}
def configure_switch_entries(self, switch_ip, port_bindings): prev_vlan = -1 prev_vni = -1 prev_port = None prev_native_vlan = 0 starttime = time.time() port_bindings.sort(key=lambda x: (x.port_id, x.vlan_id, x.vni)) self.driver.capture_and_print_timeshot( starttime, "replay_t2_aft_sort", switch=switch_ip) vlans = set() pvlans = set() interface_count = 0 duplicate_port = 0 vlan_count = 0 for port in port_bindings: if nxos_db.is_reserved_binding(port): continue auto_create, auto_trunk = self._gather_config_parms( nxos_db.is_provider_vlan(port.vlan_id), port.vlan_id) if port.port_id == prev_port: if port.vlan_id == prev_vlan and port.vni == prev_vni: duplicate_port += 1 continue else: vlan_count += 1 if auto_create: vlans.add((port.vlan_id, port.vni)) if auto_trunk: pvlans.add(port.vlan_id) if port.is_native: prev_native_vlan = port.vlan_id else: if prev_port: interface_count += 1 LOG.debug("Switch %s port %s replay summary: unique vlan " "count %d, duplicate port entries %d", switch_ip, prev_port, vlan_count, duplicate_port) duplicate_port = 0 vlan_count = 0 if pvlans: self._restore_port_binding( switch_ip, pvlans, prev_port, prev_native_vlan) pvlans.clear() prev_native_vlan = 0 if auto_create: vlans.add((port.vlan_id, port.vni)) if auto_trunk: pvlans.add(port.vlan_id) prev_port = port.port_id if port.is_native: prev_native_vlan = port.vlan_id if pvlans: LOG.debug("Switch %s port %s replay summary: unique vlan " "count %d, duplicate port entries %d", switch_ip, port.port_id, vlan_count, duplicate_port) self._restore_port_binding( switch_ip, pvlans, prev_port, prev_native_vlan) LOG.debug("Replayed total %d ports for Switch %s", interface_count + 1, switch_ip) self.driver.capture_and_print_timeshot( starttime, "replay_part_1", switch=switch_ip) vlans = list(vlans) if vlans: vlans.sort() vlan, vni = vlans[0] if vni == 0: self._save_switch_vlan_range(switch_ip, vlans) else: self._save_switch_vxlan_range(switch_ip, vlans) self.set_switch_ip_and_active_state( switch_ip, const.SWITCH_RESTORE_S2) self.configure_next_batch_of_vlans(switch_ip) self.driver.capture_and_print_timeshot( starttime, "replay_part_2", switch=switch_ip)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_resources_per_hosting_device'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'resources'},{'id': '5', 'type': 'block', 'children': ['6', '10', '71']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'hosting_devices'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '17']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'resources'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'for_statement', 'children': ['19', '20', '28']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '20', 'type': 'boolean_operator', 'children': ['21', '27'], 'value': 'or'},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'resources'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'list', 'children': [], 'value': '[]'},{'id': '28', 'type': 'block', 'children': ['29', '40', '48', '56']},{'id': '29', 'type': 'if_statement', 'children': ['30', '38']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '37'], 'value': 'is'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'string', 'children': [], 'value': "'hosting_device'"},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'continue_statement', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'hd_id'},{'id': '43', 'type': 'subscript', 'children': ['44', '47']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '46', 'type': 'string', 'children': [], 'value': "'hosting_device'"},{'id': '47', 'type': 'string', 'children': [], 'value': "'id'"},{'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': 'hosting_devices'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'hd_id'},{'id': '55', 'type': 'dictionary', 'children': []},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '69']},{'id': '58', 'type': 'attribute', 'children': ['59', '68']},{'id': '59', 'type': 'call', 'children': ['60', '65']},{'id': '60', 'type': 'attribute', 'children': ['61', '64']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'hosting_devices'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'hd_id'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '67', 'type': 'list', 'children': [], 'value': '[]'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '71', 'type': 'return_statement', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'hosting_devices'}
def _sort_resources_per_hosting_device(resources): hosting_devices = {} for key in resources.keys(): for r in resources.get(key) or []: if r.get('hosting_device') is None: continue hd_id = r['hosting_device']['id'] hosting_devices.setdefault(hd_id, {}) hosting_devices[hd_id].setdefault(key, []).append(r) return hosting_devices
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compute'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'yerr'},{'id': '8', 'type': 'float', 'children': [], 'value': '1.123e-12'},{'id': '9', 'type': 'default_parameter', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'check_sorted'},{'id': '11', 'type': 'True', 'children': []},{'id': '12', 'type': 'default_parameter', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '14', 'type': 'None', 'children': []},{'id': '15', 'type': 'default_parameter', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '17', 'type': 'None', 'children': []},{'id': '18', 'type': 'default_parameter', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'V'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22', '31', '53', '70', '76', '89', '98', '112', '128', '146', '164', '198']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'atleast_1d'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '31', 'type': 'if_statement', 'children': ['32', '47']},{'id': '32', 'type': 'boolean_operator', 'children': ['33', '34'], 'value': 'and'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'check_sorted'},{'id': '34', 'type': 'call', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '38', 'type': 'argument_list', 'children': ['39']},{'id': '39', 'type': 'comparison_operator', 'children': ['40', '46'], 'value': '<'},{'id': '40', 'type': 'call', 'children': ['41', '44']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'diff'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '46', 'type': 'float', 'children': [], 'value': '0.0'},{'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 input coordinates must be sorted"'},{'id': '53', 'type': 'if_statement', 'children': ['54', '64']},{'id': '54', 'type': 'boolean_operator', 'children': ['55', '56'], 'value': 'and'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'check_sorted'},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '63'], 'value': '>'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'shape'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'block', 'children': ['65']},{'id': '65', 'type': 'raise_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'string', 'children': [], 'value': '"dimension mismatch"'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_t'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '80', 'type': 'identifier', 'children': [], 'value': '_yerr'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'empty_like'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '88', 'type': 'identifier', 'children': [], 'value': '_t'},{'id': '89', 'type': 'expression_statement', 'children': ['90']},{'id': '90', 'type': 'assignment', 'children': ['91', '97']},{'id': '91', 'type': 'subscript', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '94', 'type': 'identifier', 'children': [], 'value': '_yerr'},{'id': '95', 'type': 'slice', 'children': ['96']},{'id': '96', 'type': 'colon', 'children': []},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'yerr'},{'id': '98', 'type': 'expression_statement', 'children': ['99']},{'id': '99', 'type': 'assignment', 'children': ['100', '107']},{'id': '100', 'type': 'tuple_pattern', 'children': ['101', '102', '103', '104', '105', '106']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'alpha_real'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'beta_real'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'alpha_complex_real'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'alpha_complex_imag'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'beta_complex_real'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'beta_complex_imag'},{'id': '107', 'type': 'attribute', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'kernel'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'coefficients'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'assignment', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': '_A'},{'id': '117', 'type': 'conditional_expression', 'children': ['118', '124', '127'], 'value': 'if'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'integer', 'children': [], 'value': '0'},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'is'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '126', 'type': 'None', 'children': []},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'A'},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '132', 'type': 'identifier', 'children': [], 'value': '_U'},{'id': '133', 'type': 'conditional_expression', 'children': ['134', '142', '145'], 'value': 'if'},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'tuple', 'children': ['140', '141']},{'id': '140', 'type': 'integer', 'children': [], 'value': '0'},{'id': '141', 'type': 'integer', 'children': [], 'value': '0'},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'is'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '144', 'type': 'None', 'children': []},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'U'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '151']},{'id': '148', 'type': 'attribute', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '150', 'type': 'identifier', 'children': [], 'value': '_V'},{'id': '151', 'type': 'conditional_expression', 'children': ['152', '160', '163'], 'value': 'if'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'empty'},{'id': '156', 'type': 'argument_list', 'children': ['157']},{'id': '157', 'type': 'tuple', 'children': ['158', '159']},{'id': '158', 'type': 'integer', 'children': [], 'value': '0'},{'id': '159', 'type': 'integer', 'children': [], 'value': '0'},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': 'is'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'V'},{'id': '162', 'type': 'None', 'children': []},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'V'},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '171']},{'id': '166', 'type': 'attribute', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'solver'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'compute'},{'id': '171', 'type': 'argument_list', 'children': ['172', '177', '178', '179', '180', '181', '182', '183', '186', '189', '192', '193']},{'id': '172', 'type': 'attribute', 'children': ['173', '176']},{'id': '173', 'type': 'attribute', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'kernel'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'jitter'},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'alpha_real'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'beta_real'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'alpha_complex_real'},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'alpha_complex_imag'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'beta_complex_real'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'beta_complex_imag'},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '185', 'type': 'identifier', 'children': [], 'value': '_A'},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '188', 'type': 'identifier', 'children': [], 'value': '_U'},{'id': '189', 'type': 'attribute', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '191', 'type': 'identifier', 'children': [], 'value': '_V'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '193', 'type': 'binary_operator', 'children': ['194', '197'], 'value': '**'},{'id': '194', 'type': 'attribute', 'children': ['195', '196']},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '196', 'type': 'identifier', 'children': [], 'value': '_yerr'},{'id': '197', 'type': 'integer', 'children': [], 'value': '2'},{'id': '198', 'type': 'expression_statement', 'children': ['199']},{'id': '199', 'type': 'assignment', 'children': ['200', '203']},{'id': '200', 'type': 'attribute', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'dirty'},{'id': '203', 'type': 'False', 'children': []}
def compute(self, t, yerr=1.123e-12, check_sorted=True, A=None, U=None, V=None): t = np.atleast_1d(t) if check_sorted and np.any(np.diff(t) < 0.0): raise ValueError("the input coordinates must be sorted") if check_sorted and len(t.shape) > 1: raise ValueError("dimension mismatch") self._t = t self._yerr = np.empty_like(self._t) self._yerr[:] = yerr (alpha_real, beta_real, alpha_complex_real, alpha_complex_imag, beta_complex_real, beta_complex_imag) = self.kernel.coefficients self._A = np.empty(0) if A is None else A self._U = np.empty((0, 0)) if U is None else U self._V = np.empty((0, 0)) if V is None else V self.solver.compute( self.kernel.jitter, alpha_real, beta_real, alpha_complex_real, alpha_complex_imag, beta_complex_real, beta_complex_imag, self._A, self._U, self._V, t, self._yerr**2 ) self.dirty = False
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'group_dict'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'keyfunc'},{'id': '6', 'type': 'block', 'children': ['7', '16', '36']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'result'},{'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': 'list'},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '19']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '19', 'type': 'block', 'children': ['20', '27']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'keyfunc'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'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': 'result'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '36', 'type': 'return_statement', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'result'}
def group_dict(items, keyfunc): result = collections.defaultdict(list) for i in items: key = keyfunc(i) result[key].append(i) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_split_dict'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '5', 'type': 'block', 'children': ['6', '8', '19']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''Split dict into sorted keys and values\n >>> _split_dict({'b': 2, 'a': 1})\n (['a', 'b'], [1, 2])\n '''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'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': 'dic'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'return_statement', 'children': ['20']},{'id': '20', 'type': 'expression_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '22', 'type': 'list_comprehension', 'children': ['23', '26']},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'dic'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'keys'}
def _split_dict(dic): '''Split dict into sorted keys and values >>> _split_dict({'b': 2, 'a': 1}) (['a', 'b'], [1, 2]) ''' keys = sorted(dic.keys()) return keys, [dic[k] for k in keys]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'monitor'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '5', 'type': 'block', 'children': ['6', '8', '22', '30', '52', '70', '82', '124']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "''' Retrieve status of jobs submitted from a given workspace, as a list\n of TSV lines sorted by descending order of job submission date'''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'fapi'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'list_submissions'},{'id': '15', 'type': 'argument_list', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'project'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'workspace'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'fapi'},{'id': '26', 'type': 'identifier', 'children': [], 'value': '_check_response_code'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '29', 'type': 'integer', 'children': [], 'value': '200'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'statuses'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '35', 'type': 'argument_list', 'children': ['36', '41', '49']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '40', 'type': 'argument_list', 'children': []},{'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '43', 'type': 'lambda', 'children': ['44', '46']},{'id': '44', 'type': 'lambda_parameters', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '48', 'type': 'string', 'children': [], 'value': "'submissionDate'"},{'id': '49', 'type': 'keyword_argument', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '51', 'type': 'True', 'children': []},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'call', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'statuses'},{'id': '67', 'type': 'integer', 'children': [], 'value': '0'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'keys'},{'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': 'expander'},{'id': '73', 'type': 'lambda', 'children': ['74', '76']},{'id': '74', 'type': 'lambda_parameters', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "'{0}'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '82', 'type': 'function_definition', 'children': ['83', '84', '86']},{'id': '83', 'type': 'function_name', 'children': [], 'value': 'expander'},{'id': '84', 'type': 'parameters', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'thing'},{'id': '86', 'type': 'block', 'children': ['87', '117']},{'id': '87', 'type': 'if_statement', 'children': ['88', '93']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '90', 'type': 'argument_list', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'thing'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '93', 'type': 'block', 'children': ['94', '104']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'entityType'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'thing'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '101', 'type': 'argument_list', 'children': ['102', '103']},{'id': '102', 'type': 'string', 'children': [], 'value': '"entityType"'},{'id': '103', 'type': 'None', 'children': []},{'id': '104', 'type': 'if_statement', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'entityType'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'return_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'string', 'children': [], 'value': '"{0}:{1}"'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '112', 'type': 'argument_list', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'entityType'},{'id': '114', 'type': 'subscript', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'thing'},{'id': '116', 'type': 'string', 'children': [], 'value': "'entityName'"},{'id': '117', 'type': 'return_statement', 'children': ['118']},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'string', 'children': [], 'value': '"{0}"'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'thing'},{'id': '124', 'type': 'return_statement', 'children': ['125']},{'id': '125', 'type': 'binary_operator', 'children': ['126', '128'], 'value': '+'},{'id': '126', 'type': 'list', 'children': ['127'], 'value': '[header]'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'header'},{'id': '128', 'type': 'list_comprehension', 'children': ['129', '143']},{'id': '129', 'type': 'call', 'children': ['130', '133']},{'id': '130', 'type': 'attribute', 'children': ['131', '132']},{'id': '131', 'type': 'string', 'children': [], 'value': "'\\t'"},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '133', 'type': 'argument_list', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '136']},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '136', 'type': 'argument_list', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'expander'},{'id': '138', 'type': 'call', 'children': ['139', '142']},{'id': '139', 'type': 'attribute', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '142', 'type': 'argument_list', 'children': []},{'id': '143', 'type': 'for_in_clause', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'statuses'}
def monitor(args): ''' Retrieve status of jobs submitted from a given workspace, as a list of TSV lines sorted by descending order of job submission date''' r = fapi.list_submissions(args.project, args.workspace) fapi._check_response_code(r, 200) statuses = sorted(r.json(), key=lambda k: k['submissionDate'], reverse=True) header = '\t'.join(list(statuses[0].keys())) expander = lambda v: '{0}'.format(v) def expander(thing): if isinstance(thing, dict): entityType = thing.get("entityType", None) if entityType: return "{0}:{1}".format(entityType, thing['entityName']) return "{0}".format(thing) return [header] + ['\t'.join( map(expander, v.values())) for v in statuses]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'tcsort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'binary_operator', 'children': ['8', '14'], 'value': '+'},{'id': '8', 'type': 'call', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '10', 'type': 'argument_list', 'children': ['11']},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '13', 'type': 'integer', 'children': [], 'value': '1'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '16', 'type': 'generator_expression', 'children': ['17', '21']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'tcsort'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'kv'},{'id': '21', 'type': 'for_in_clause', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'kv'},{'id': '23', 'type': 'call', 'children': ['24', '29']},{'id': '24', 'type': 'attribute', 'children': ['25', '28']},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '27', 'type': 'integer', 'children': [], 'value': '1'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '29', 'type': 'argument_list', 'children': []}
def tcsort(item): return len(item[1]) + sum(tcsort(kv) for kv in item[1].items())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sortProperties'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '6', 'type': 'block', 'children': ['7', '28']},{'id': '7', 'type': 'for_statement', 'children': ['8', '11', '16']},{'id': '8', 'type': 'pattern_list', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'prop'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'objects'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_globalSortKey'},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '31', 'type': 'argument_list', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'properties'},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '35', 'type': 'lambda', 'children': ['36', '38']},{'id': '36', 'type': 'lambda_parameters', 'children': ['37']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '38', 'type': 'subscript', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'predicate_rank'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'p'}
def sortProperties(self, properties): for prop, objects in properties.items(): objects.sort(key=self._globalSortKey) return sorted(properties, key=lambda p: self.predicate_rank[p])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'getSubOrder'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'existing'},{'id': '5', 'type': 'block', 'children': ['6', '46', '50', '106', '115', '127', '136']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'alpha'},{'id': '9', 'type': 'subscript', 'children': ['10', '45']},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'list_splat', 'children': ['17']},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '19', 'type': 'argument_list', 'children': ['20', '37']},{'id': '20', 'type': 'generator_expression', 'children': ['21', '28']},{'id': '21', 'type': 'tuple', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '23', 'type': 'subscript', 'children': ['24', '27']},{'id': '24', 'type': 'subscript', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '26', 'type': 'string', 'children': [], 'value': "'rec'"},{'id': '27', 'type': 'string', 'children': [], 'value': "'label'"},{'id': '28', 'type': 'for_in_clause', 'children': ['29', '32']},{'id': '29', 'type': 'pattern_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'existing'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '36', 'type': 'argument_list', 'children': []},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '39', 'type': 'lambda', 'children': ['40', '42']},{'id': '40', 'type': 'lambda_parameters', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '44', 'type': 'integer', 'children': [], 'value': '1'},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'expression_statement', 'children': ['47']},{'id': '47', 'type': 'assignment', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'depths'},{'id': '49', 'type': 'dictionary', 'children': []},{'id': '50', 'type': 'function_definition', 'children': ['51', '52', '54']},{'id': '51', 'type': 'function_name', 'children': [], 'value': 'getDepth'},{'id': '52', 'type': 'parameters', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'if_statement', 'children': ['56', '59', '64']},{'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'in'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'depths'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'depths'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '64', 'type': 'else_clause', 'children': ['65']},{'id': '65', 'type': 'block', 'children': ['66']},{'id': '66', 'type': 'if_statement', 'children': ['67', '70', '101']},{'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'in'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'existing'},{'id': '70', 'type': 'block', 'children': ['71', '82', '97']},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'names_above'},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'getDepth'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'subscript', 'children': ['78', '81']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'existing'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '81', 'type': 'string', 'children': [], 'value': "'sc'"},{'id': '82', 'type': 'expression_statement', 'children': ['83']},{'id': '83', 'type': 'assignment', 'children': ['84', '87']},{'id': '84', 'type': 'subscript', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'depths'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '+'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'names_above'},{'id': '89', 'type': 'list', 'children': ['90'], 'value': "[existing[id_]['rec']['label']]"},{'id': '90', 'type': 'subscript', 'children': ['91', '96']},{'id': '91', 'type': 'subscript', 'children': ['92', '95']},{'id': '92', 'type': 'subscript', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'existing'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '95', 'type': 'string', 'children': [], 'value': "'rec'"},{'id': '96', 'type': 'string', 'children': [], 'value': "'label'"},{'id': '97', 'type': 'return_statement', 'children': ['98']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'depths'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '101', 'type': 'else_clause', 'children': ['102']},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'list', 'children': ['105'], 'value': "['']"},{'id': '105', 'type': 'string', 'children': [], 'value': "''"},{'id': '106', 'type': 'for_statement', 'children': ['107', '108', '109']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'existing'},{'id': '109', 'type': 'block', 'children': ['110']},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'call', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'getDepth'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'call', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'print'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '126']},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'depths'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '126', 'type': 'argument_list', 'children': []},{'id': '127', 'type': 'function_definition', 'children': ['128', '129', '131']},{'id': '128', 'type': 'function_name', 'children': [], 'value': 'key_'},{'id': '129', 'type': 'parameters', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '131', 'type': 'block', 'children': ['132']},{'id': '132', 'type': 'return_statement', 'children': ['133']},{'id': '133', 'type': 'subscript', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'depths'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '136', 'type': 'return_statement', 'children': ['137']},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '139', 'type': 'argument_list', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'depths'},{'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'key_'}
def getSubOrder(existing): alpha = list(zip(*sorted(((k, v['rec']['label']) for k, v in existing.items()), key=lambda a: a[1])))[0] depths = {} def getDepth(id_): if id_ in depths: return depths[id_] else: if id_ in existing: names_above = getDepth(existing[id_]['sc']) depths[id_] = names_above + [existing[id_]['rec']['label']] return depths[id_] else: return [''] for id_ in existing: getDepth(id_) print(sorted(depths.values())) def key_(id_): return depths[id_] return sorted(depths, key=key_)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'insert_sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '6', 'type': 'block', 'children': ['7', '13', '19', '36']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'collator'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'Collator'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'createInstance'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'conditional_expression', 'children': ['28', '32', '33'], 'value': 'if'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'Locale'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'Locale'},{'id': '35', 'type': 'argument_list', 'children': []},{'id': '36', 'type': 'for_statement', 'children': ['37', '38', '41', '71']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '41', 'type': 'block', 'children': ['42']},{'id': '42', 'type': 'if_statement', 'children': ['43', '62']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '61'], 'value': '>'},{'id': '44', 'type': 'call', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'collator'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'compare'},{'id': '48', 'type': 'argument_list', 'children': ['49', '55']},{'id': '49', 'type': 'boolean_operator', 'children': ['50', '54'], 'value': 'or'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'child'},{'id': '54', 'type': 'string', 'children': [], 'value': "''"},{'id': '55', 'type': 'boolean_operator', 'children': ['56', '60'], 'value': 'or'},{'id': '56', 'type': 'call', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '60', 'type': 'string', 'children': [], 'value': "''"},{'id': '61', 'type': 'integer', 'children': [], 'value': '0'},{'id': '62', 'type': 'block', 'children': ['63', '70']},{'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': 'child'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'addprevious'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '70', 'type': 'break_statement', 'children': []},{'id': '71', 'type': 'else_clause', 'children': ['72']},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '80']},{'id': '75', 'type': 'attribute', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'node'}
def insert_sort(node, target): sort = target.sort lang = target.lang collator = Collator.createInstance(Locale(lang) if lang else Locale()) for child in target.tree: if collator.compare(sort(child) or '', sort(node) or '') > 0: child.addprevious(node) break else: target.tree.append(node)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_sort_by'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'decl'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'pseudo'},{'id': '8', 'type': 'block', 'children': ['9', '40', '64', '76', '84', '90', '100', '106', '112']},{'id': '9', 'type': 'if_statement', 'children': ['10', '15', '28']},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '12'], 'value': 'in'},{'id': '11', 'type': 'string', 'children': [], 'value': "','"},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'decl'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '15', 'type': 'block', 'children': ['16']},{'id': '16', 'type': 'expression_statement', 'children': ['17']},{'id': '17', 'type': 'assignment', 'children': ['18', '21']},{'id': '18', 'type': 'pattern_list', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'css'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '23', 'type': 'argument_list', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'decl'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '27', 'type': 'string', 'children': [], 'value': "','"},{'id': '28', 'type': 'else_clause', 'children': ['29']},{'id': '29', 'type': 'block', 'children': ['30', '36']},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'css'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'decl'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'css_to_func'},{'id': '45', 'type': 'argument_list', 'children': ['46', '50', '56', '59']},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'serialize'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'css'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'serialize'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'boolean_operator', 'children': ['54', '55'], 'value': 'or'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'flags'},{'id': '55', 'type': 'string', 'children': [], 'value': "''"},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'css_namespaces'},{'id': '59', 'type': 'subscript', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '63', 'type': 'string', 'children': [], 'value': "'lang'"},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'step'},{'id': '67', 'type': 'subscript', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '71', 'type': 'subscript', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '75', 'type': 'string', 'children': [], 'value': "'current_step'"},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'assignment', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'current_target'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '95']},{'id': '92', 'type': 'attribute', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'lang'},{'id': '95', 'type': 'subscript', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '99', 'type': 'string', 'children': [], 'value': "'lang'"},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '105']},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'isgroup'},{'id': '105', 'type': 'False', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '111', 'type': 'None', 'children': []},{'id': '112', 'type': 'for_statement', 'children': ['113', '116', '117', '126']},{'id': '113', 'type': 'pattern_list', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'pos'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '116', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '117', 'type': 'call', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'call', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'reversed'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'subscript', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'step'},{'id': '125', 'type': 'string', 'children': [], 'value': "'actions'"},{'id': '126', 'type': 'block', 'children': ['127']},{'id': '127', 'type': 'if_statement', 'children': ['128', '144']},{'id': '128', 'type': 'boolean_operator', 'children': ['129', '134', '135'], 'value': 'and'},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '133'], 'value': '=='},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '132', 'type': 'integer', 'children': [], 'value': '0'},{'id': '133', 'type': 'string', 'children': [], 'value': "'target'"},{'id': '134', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '135', 'type': 'comparison_operator', 'children': ['136', '141'], 'value': '=='},{'id': '136', 'type': 'attribute', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '139', 'type': 'integer', 'children': [], 'value': '1'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'tree'},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'element'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'etree_element'},{'id': '144', 'type': 'block', 'children': ['145', '153', '161', '169']},{'id': '145', 'type': 'expression_statement', 'children': ['146']},{'id': '146', 'type': 'assignment', 'children': ['147', '152']},{'id': '147', 'type': 'attribute', 'children': ['148', '151']},{'id': '148', 'type': 'subscript', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '150', 'type': 'integer', 'children': [], 'value': '1'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'assignment', 'children': ['155', '160']},{'id': '155', 'type': 'attribute', 'children': ['156', '159']},{'id': '156', 'type': 'subscript', 'children': ['157', '158']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '158', 'type': 'integer', 'children': [], 'value': '1'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'isgroup'},{'id': '160', 'type': 'False', 'children': []},{'id': '161', 'type': 'expression_statement', 'children': ['162']},{'id': '162', 'type': 'assignment', 'children': ['163', '168']},{'id': '163', 'type': 'attribute', 'children': ['164', '167']},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'action'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'groupby'},{'id': '168', 'type': 'None', 'children': []},{'id': '169', 'type': 'break_statement', 'children': []}
def do_sort_by(self, element, decl, pseudo): if ',' in decl.value: css, flags = split(decl.value, ',') else: css = decl.value flags = None sort = css_to_func(serialize(css), serialize(flags or ''), self.css_namespaces, self.state['lang']) step = self.state[self.state['current_step']] target = self.current_target() target.sort = sort target.lang = self.state['lang'] target.isgroup = False target.groupby = None for pos, action in \ enumerate(reversed(step['actions'])): if action[0] == 'target' and \ action[1].tree == element.etree_element: action[1].sort = sort action[1].isgroup = False action[1].groupby = None break
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'keys'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '45']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '11', 'type': 'argument_list', 'children': []},{'id': '12', 'type': 'for_statement', 'children': ['13', '14', '21']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'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': 'self'},{'id': '21', 'type': 'block', 'children': ['22', '30']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_value'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'if_statement', 'children': ['31', '37']},{'id': '31', 'type': 'not_operator', 'children': ['32']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'in'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '34', 'type': 'list', 'children': ['35', '36'], 'value': "['', None]"},{'id': '35', 'type': 'string', 'children': [], 'value': "''"},{'id': '36', 'type': 'None', 'children': []},{'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': 'keys'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '45', 'type': 'return_statement', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'keys'}
def keys(self): keys = list() for n in range(len(self)): key = self.get_value() if not key in ['', None]: keys.append(key) return keys
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_item'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '7', 'type': 'block', 'children': ['8', '19']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '11', 'type': 'call', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '13', 'type': 'argument_list', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'if_statement', 'children': ['20', '23', '41']},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'in'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'set_value'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31', '37']},{'id': '30', 'type': 'integer', 'children': [], 'value': '1'},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '41', 'type': 'else_clause', 'children': ['42']},{'id': '42', 'type': 'block', 'children': ['43', '58']},{'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': 'self'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'set_value'},{'id': '48', 'type': 'argument_list', 'children': ['49', '50', '54']},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'key'},{'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': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'set_value'},{'id': '63', 'type': 'argument_list', 'children': ['64', '65', '71']},{'id': '64', 'type': 'integer', 'children': [], 'value': '1'},{'id': '65', 'type': 'binary_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': 'self'},{'id': '70', 'type': 'integer', 'children': [], 'value': '1'},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'value'}
def set_item(self, key, value): keys = list(self.keys()) if key in keys: self.set_value(1,keys.index(key),str(value)) else: self.set_value(0,len(self), str(key)) self.set_value(1,len(self)-1, str(value))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'insert_ordered'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '6', 'type': 'block', 'children': ['7', '11', '35', '43']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '10', 'type': 'integer', 'children': [], 'value': '0'},{'id': '11', 'type': 'for_statement', 'children': ['12', '13', '21']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'array'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'if_statement', 'children': ['23', '28']},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': '>='},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'n'},{'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': 'index'},{'id': '32', 'type': 'binary_operator', 'children': ['33', '34'], 'value': '+'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'array'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '43', 'type': 'return_statement', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'index'}
def insert_ordered(value, array): index = 0 for n in range(0,len(array)): if value >= array[n]: index = n+1 array.insert(index, value) return index
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_dataset'},{'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': 'dataset'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '10', 'type': 'block', 'children': ['11', '18', '38', '48', '100', '106', '129', '135', '141', '153', '161', '169', '175', '196']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': '_kwargs_checks'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '18', 'type': 'if_statement', 'children': ['19', '32']},{'id': '19', 'type': 'boolean_operator', 'children': ['20', '23'], 'value': 'and'},{'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'not_operator', 'children': ['24']},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'len'},{'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': 'kwargs'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'block', 'children': ['33']},{'id': '33', 'type': 'raise_statement', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'string', 'children': [], 'value': '"must provide some value to filter for datasets"'},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '45', 'type': 'argument_list', 'children': ['46', '47']},{'id': '46', 'type': 'string', 'children': [], 'value': "'kind'"},{'id': '47', 'type': 'None', 'children': []},{'id': '48', 'type': 'if_statement', 'children': ['49', '52']},{'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'is'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '51', 'type': 'None', 'children': []},{'id': '52', 'type': 'block', 'children': ['53', '65', '69', '94']},{'id': '53', 'type': 'if_statement', 'children': ['54', '59']},{'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': 'kind'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '63', 'type': 'list', 'children': ['64'], 'value': '[kind]'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'kind_deps'},{'id': '68', 'type': 'list', 'children': [], 'value': '[]'},{'id': '69', 'type': 'for_statement', 'children': ['70', '71', '72']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'kind_i'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '72', 'type': 'block', 'children': ['73', '82']},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "'{}_dep'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'kind_i'},{'id': '82', 'type': 'if_statement', 'children': ['83', '86']},{'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'not'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '86', 'type': 'block', 'children': ['87']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'call', 'children': ['89', '92']},{'id': '89', 'type': 'attribute', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'kind_deps'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'dep'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '97', 'type': 'binary_operator', 'children': ['98', '99'], 'value': '+'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'kind_deps'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '105']},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '104', 'type': 'string', 'children': [], 'value': "'kind'"},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'kind'},{'id': '106', 'type': 'if_statement', 'children': ['107', '110']},{'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'is'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '109', 'type': 'None', 'children': []},{'id': '110', 'type': 'block', 'children': ['111', '123']},{'id': '111', 'type': 'expression_statement', 'children': ['112']},{'id': '112', 'type': 'assignment', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '114', 'type': 'attribute', 'children': ['115', '122']},{'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': 'filter'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'dictionary_splat', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'datasets'},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '128']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '127', 'type': 'string', 'children': [], 'value': "'kind'"},{'id': '128', 'type': 'None', 'children': []},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '134']},{'id': '131', 'type': 'subscript', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '133', 'type': 'string', 'children': [], 'value': "'dataset'"},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '135', 'type': 'expression_statement', 'children': ['136']},{'id': '136', 'type': 'assignment', 'children': ['137', '140']},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '139', 'type': 'string', 'children': [], 'value': "'qualifier'"},{'id': '140', 'type': 'None', 'children': []},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'call', 'children': ['143', '146']},{'id': '143', 'type': 'attribute', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '146', 'type': 'argument_list', 'children': ['147', '148']},{'id': '147', 'type': 'string', 'children': [], 'value': "'context'"},{'id': '148', 'type': 'list', 'children': ['149', '150', '151', '152'], 'value': "['dataset', 'model', 'constraint', 'compute']"},{'id': '149', 'type': 'string', 'children': [], 'value': "'dataset'"},{'id': '150', 'type': 'string', 'children': [], 'value': "'model'"},{'id': '151', 'type': 'string', 'children': [], 'value': "'constraint'"},{'id': '152', 'type': 'string', 'children': [], 'value': "'compute'"},{'id': '153', 'type': 'expression_statement', 'children': ['154']},{'id': '154', 'type': 'call', 'children': ['155', '158']},{'id': '155', 'type': 'attribute', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'remove_parameters_all'},{'id': '158', 'type': 'argument_list', 'children': ['159']},{'id': '159', 'type': 'dictionary_splat', 'children': ['160']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'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': 'self'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'remove_parameters_all'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'dictionary_splat', 'children': ['168']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '169', 'type': 'expression_statement', 'children': ['170']},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '173', 'type': 'identifier', 'children': [], 'value': '_handle_dataset_selectparams'},{'id': '174', 'type': 'argument_list', 'children': []},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '179', 'type': 'identifier', 'children': [], 'value': '_add_history'},{'id': '180', 'type': 'argument_list', 'children': ['181', '184', '190', '193']},{'id': '181', 'type': 'keyword_argument', 'children': ['182', '183']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'redo_func'},{'id': '183', 'type': 'string', 'children': [], 'value': "'remove_dataset'"},{'id': '184', 'type': 'keyword_argument', 'children': ['185', '186']},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'redo_kwargs'},{'id': '186', 'type': 'dictionary', 'children': ['187']},{'id': '187', 'type': 'pair', 'children': ['188', '189']},{'id': '188', 'type': 'string', 'children': [], 'value': "'dataset'"},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'dataset'},{'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'undo_func'},{'id': '192', 'type': 'None', 'children': []},{'id': '193', 'type': 'keyword_argument', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'undo_kwargs'},{'id': '195', 'type': 'dictionary', 'children': []},{'id': '196', 'type': 'return_statement', 'children': []}
def remove_dataset(self, dataset=None, **kwargs): self._kwargs_checks(kwargs) if dataset is None and not len(kwargs.items()): raise ValueError("must provide some value to filter for datasets") kind = kwargs.get('kind', None) if kind is not None: if isinstance(kind, str): kind = [kind] kind_deps = [] for kind_i in kind: dep = '{}_dep'.format(kind_i) if dep not in kind: kind_deps.append(dep) kind = kind + kind_deps kwargs['kind'] = kind if dataset is None: dataset = self.filter(**kwargs).datasets kwargs['kind'] = None kwargs['dataset'] = dataset kwargs['qualifier'] = None kwargs.setdefault('context', ['dataset', 'model', 'constraint', 'compute']) self.remove_parameters_all(**kwargs) self.remove_parameters_all(**kwargs) self._handle_dataset_selectparams() self._add_history(redo_func='remove_dataset', redo_kwargs={'dataset': dataset}, undo_func=None, undo_kwargs={}) return
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'calls_sorted'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '73', '79', '95', '103']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']},{'id': '7', 'type': 'function_name', 'children': [], 'value': '_z'},{'id': '8', 'type': 'parameters', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'if_statement', 'children': ['12', '23', '39', '66']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '14', 'type': 'argument_list', 'children': ['15', '20']},{'id': '15', 'type': 'attribute', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'ndarray'},{'id': '23', 'type': 'block', 'children': ['24']},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'mean'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'call', 'children': ['31', '38']},{'id': '31', 'type': 'attribute', 'children': ['32', '37']},{'id': '32', 'type': 'attribute', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'flatten'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'elif_clause', 'children': ['40', '59']},{'id': '40', 'type': 'boolean_operator', 'children': ['41', '50'], 'value': 'or'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '43', 'type': 'argument_list', 'children': ['44', '49']},{'id': '44', 'type': 'attribute', 'children': ['45', '48']},{'id': '45', 'type': 'attribute', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'float'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '52', 'type': 'argument_list', 'children': ['53', '58']},{'id': '53', 'type': 'attribute', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '59', 'type': 'block', 'children': ['60']},{'id': '60', 'type': 'return_statement', 'children': ['61']},{'id': '61', 'type': 'attribute', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'call'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'z'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '66', 'type': 'else_clause', 'children': ['67']},{'id': '67', 'type': 'block', 'children': ['68']},{'id': '68', 'type': 'return_statement', 'children': ['69']},{'id': '69', 'type': 'unary_operator', 'children': ['70'], 'value': '-'},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'inf'},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'calls'},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': '_calls'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'zs'},{'id': '82', 'type': 'call', 'children': ['83', '86']},{'id': '83', 'type': 'attribute', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'list_comprehension', 'children': ['88', '92']},{'id': '88', 'type': 'call', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': '_z'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '92', 'type': 'for_in_clause', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'calls'},{'id': '95', 'type': 'expression_statement', 'children': ['96']},{'id': '96', 'type': 'assignment', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'sorted_inds'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'zs'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '102', 'type': 'argument_list', 'children': []},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': '_call'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'make_callgroup'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '120']},{'id': '110', 'type': 'attribute', 'children': ['111', '119']},{'id': '111', 'type': 'subscript', 'children': ['112', '118']},{'id': '112', 'type': 'call', 'children': ['113', '116']},{'id': '113', 'type': 'attribute', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '116', 'type': 'argument_list', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'calls'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'sorted_inds'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'tolist'},{'id': '120', 'type': 'argument_list', 'children': []}
def calls_sorted(self): def _z(call): if isinstance(call.z.value, np.ndarray): return np.mean(call.z.value.flatten()) elif isinstance(call.z.value, float) or isinstance(call.z.value, int): return call.z.value else: return -np.inf calls = self._calls zs = np.array([_z(c) for c in calls]) sorted_inds = zs.argsort() return _call.make_callgroup(np.array(calls)[sorted_inds].tolist())
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_filter_library_state'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '6', 'type': 'block', 'children': ['7', '13', '19', '32', '40', '46']},{'id': '7', 'type': 'if_statement', 'children': ['8', '10']},{'id': '8', 'type': 'not_operator', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '10', 'type': 'block', 'children': ['11']},{'id': '11', 'type': 'return_statement', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'top_most_item'},{'id': '16', 'type': 'subscript', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '18', 'type': 'integer', 'children': [], 'value': '0'},{'id': '19', 'type': 'expression_statement', 'children': ['20']},{'id': '20', 'type': 'assignment', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'top_most_state_v'},{'id': '22', 'type': 'conditional_expression', 'children': ['23', '24', '29'], 'value': 'if'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'top_most_item'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '26', 'type': 'argument_list', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'top_most_item'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'StateView'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'top_most_item'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '35', 'type': 'attribute', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'top_most_state_v'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'model'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '40', 'type': 'expression_statement', 'children': ['41']},{'id': '41', 'type': 'assignment', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'global_gui_config'},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'gui_helper_state_machine'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'global_gui_config'},{'id': '46', 'type': 'if_statement', 'children': ['47', '53', '84']},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'global_gui_config'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'get_config_value'},{'id': '51', 'type': 'argument_list', 'children': ['52']},{'id': '52', 'type': 'string', 'children': [], 'value': "'STATE_SELECTION_INSIDE_LIBRARY_STATE_ENABLED'"},{'id': '53', 'type': 'block', 'children': ['54', '82']},{'id': '54', 'type': 'if_statement', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'is_root_state_of_library'},{'id': '58', 'type': 'block', 'children': ['59', '74']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'new_topmost_item'},{'id': '62', 'type': 'call', 'children': ['63', '70']},{'id': '63', 'type': 'attribute', 'children': ['64', '69']},{'id': '64', 'type': 'attribute', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'canvas'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'get_view_for_core_element'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'dismiss_upper_items'},{'id': '79', 'type': 'argument_list', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'new_topmost_item'},{'id': '82', 'type': 'return_statement', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '84', 'type': 'else_clause', 'children': ['85']},{'id': '85', 'type': 'block', 'children': ['86', '94', '124']},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'library_root_state'},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'state'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'get_uppermost_library_root_state'},{'id': '93', 'type': 'argument_list', 'children': []},{'id': '94', 'type': 'if_statement', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'library_root_state'},{'id': '96', 'type': 'block', 'children': ['97', '103', '116']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'assignment', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'library_state'},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'library_root_state'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'library_state_v'},{'id': '106', 'type': 'call', 'children': ['107', '114']},{'id': '107', 'type': 'attribute', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'canvas'},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'get_view_for_core_element'},{'id': '114', 'type': 'argument_list', 'children': ['115']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'library_state'},{'id': '116', 'type': 'return_statement', 'children': ['117']},{'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': 'dismiss_upper_items'},{'id': '121', 'type': 'argument_list', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'library_state_v'},{'id': '124', 'type': 'return_statement', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'items'}
def _filter_library_state(self, items): if not items: return items top_most_item = items[0] top_most_state_v = top_most_item if isinstance(top_most_item, StateView) else top_most_item.parent state = top_most_state_v.model.state global_gui_config = gui_helper_state_machine.global_gui_config if global_gui_config.get_config_value('STATE_SELECTION_INSIDE_LIBRARY_STATE_ENABLED'): if state.is_root_state_of_library: new_topmost_item = self.view.canvas.get_view_for_core_element(state.parent) return self.dismiss_upper_items(items, new_topmost_item) return items else: library_root_state = state.get_uppermost_library_root_state() if library_root_state: library_state = library_root_state.parent library_state_v = self.view.canvas.get_view_for_core_element(library_state) return self.dismiss_upper_items(items, library_state_v) return items
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_filter_hovered_items'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '7', 'type': 'block', 'children': ['8', '17', '23', '29', '43', '63', '76', '222', '258']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '11', 'type': 'call', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': '_filter_library_state'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '17', 'type': 'if_statement', 'children': ['18', '20']},{'id': '18', 'type': 'not_operator', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '20', 'type': 'block', 'children': ['21']},{'id': '21', 'type': 'return_statement', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'top_most_item'},{'id': '26', 'type': 'subscript', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'second_top_most_item'},{'id': '32', 'type': 'conditional_expression', 'children': ['33', '36', '42'], 'value': 'if'},{'id': '33', 'type': 'subscript', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '35', 'type': 'integer', 'children': [], 'value': '1'},{'id': '36', 'type': 'comparison_operator', 'children': ['37', '41'], 'value': '>'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '41', 'type': 'integer', 'children': [], 'value': '1'},{'id': '42', 'type': 'None', 'children': []},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'first_state_v'},{'id': '46', 'type': 'call', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'next'},{'id': '48', 'type': 'argument_list', 'children': ['49']},{'id': '49', 'type': 'call', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '51', 'type': 'argument_list', 'children': ['52', '62']},{'id': '52', 'type': 'lambda', 'children': ['53', '55']},{'id': '53', 'type': 'lambda_parameters', 'children': ['54']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '59', 'type': 'tuple', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'NameView'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'StateView'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'first_state_v'},{'id': '66', 'type': 'conditional_expression', 'children': ['67', '70', '75'], 'value': 'if'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'first_state_v'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'parent'},{'id': '70', 'type': 'call', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '72', 'type': 'argument_list', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'first_state_v'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'NameView'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'first_state_v'},{'id': '76', 'type': 'if_statement', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'first_state_v'},{'id': '78', 'type': 'block', 'children': ['79', '106', '110', '118', '139', '150', '189']},{'id': '79', 'type': 'for_statement', 'children': ['80', '81', '82']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '82', 'type': 'block', 'children': ['83', '105']},{'id': '83', 'type': 'if_statement', 'children': ['84', '89']},{'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': 'item'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'ConnectionView'},{'id': '89', 'type': 'block', 'children': ['90']},{'id': '90', 'type': 'if_statement', 'children': ['91', '103']},{'id': '91', 'type': 'comparison_operator', 'children': ['92', '102'], 'value': 'is'},{'id': '92', 'type': 'call', 'children': ['93', '100']},{'id': '93', 'type': 'attribute', 'children': ['94', '99']},{'id': '94', 'type': 'attribute', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'canvas'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'get_parent'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'top_most_item'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'first_state_v'},{'id': '103', 'type': 'block', 'children': ['104']},{'id': '104', 'type': 'continue_statement', 'children': []},{'id': '105', 'type': 'break_statement', 'children': []},{'id': '106', 'type': 'expression_statement', 'children': ['107']},{'id': '107', 'type': 'assignment', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'port_beneath_cursor'},{'id': '109', 'type': 'False', 'children': []},{'id': '110', 'type': 'expression_statement', 'children': ['111']},{'id': '111', 'type': 'assignment', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'state_ports'},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'first_state_v'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'get_all_ports'},{'id': '117', 'type': 'argument_list', 'children': []},{'id': '118', 'type': 'expression_statement', 'children': ['119']},{'id': '119', 'type': 'assignment', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '121', 'type': 'call', 'children': ['122', '132']},{'id': '122', 'type': 'attribute', 'children': ['123', '131']},{'id': '123', 'type': 'call', 'children': ['124', '129']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'get_matrix_v2i'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'first_state_v'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'transform_point'},{'id': '132', 'type': 'argument_list', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '136', 'type': 'attribute', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'event'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '142']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'i2v_matrix'},{'id': '142', 'type': 'call', 'children': ['143', '148']},{'id': '143', 'type': 'attribute', 'children': ['144', '147']},{'id': '144', 'type': 'attribute', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'get_matrix_i2v'},{'id': '148', 'type': 'argument_list', 'children': ['149']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'first_state_v'},{'id': '150', 'type': 'for_statement', 'children': ['151', '152', '153']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'port_v'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'state_ports'},{'id': '153', 'type': 'block', 'children': ['154', '167', '179']},{'id': '154', 'type': 'expression_statement', 'children': ['155']},{'id': '155', 'type': 'assignment', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'item_distance'},{'id': '157', 'type': 'subscript', 'children': ['158', '166']},{'id': '158', 'type': 'call', 'children': ['159', '164']},{'id': '159', 'type': 'attribute', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'port_v'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'port'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'glue'},{'id': '164', 'type': 'argument_list', 'children': ['165']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'position'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'view_distance'},{'id': '170', 'type': 'subscript', 'children': ['171', '178']},{'id': '171', 'type': 'call', 'children': ['172', '175']},{'id': '172', 'type': 'attribute', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'i2v_matrix'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'transform_distance'},{'id': '175', 'type': 'argument_list', 'children': ['176', '177']},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'item_distance'},{'id': '177', 'type': 'integer', 'children': [], 'value': '0'},{'id': '178', 'type': 'integer', 'children': [], 'value': '0'},{'id': '179', 'type': 'if_statement', 'children': ['180', '183']},{'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '=='},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'view_distance'},{'id': '182', 'type': 'integer', 'children': [], 'value': '0'},{'id': '183', 'type': 'block', 'children': ['184', '188']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'assignment', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'port_beneath_cursor'},{'id': '187', 'type': 'True', 'children': []},{'id': '188', 'type': 'break_statement', 'children': []},{'id': '189', 'type': 'if_statement', 'children': ['190', '191']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'port_beneath_cursor'},{'id': '191', 'type': 'block', 'children': ['192', '202', '208']},{'id': '192', 'type': 'expression_statement', 'children': ['193']},{'id': '193', 'type': 'assignment', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '195', 'type': 'call', 'children': ['196', '199']},{'id': '196', 'type': 'attribute', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'dismiss_upper_items'},{'id': '199', 'type': 'argument_list', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'assignment', 'children': ['204', '205']},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'top_most_item'},{'id': '205', 'type': 'subscript', 'children': ['206', '207']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '207', 'type': 'integer', 'children': [], 'value': '0'},{'id': '208', 'type': 'expression_statement', 'children': ['209']},{'id': '209', 'type': 'assignment', 'children': ['210', '211']},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'second_top_most_item'},{'id': '211', 'type': 'conditional_expression', 'children': ['212', '215', '221'], 'value': 'if'},{'id': '212', 'type': 'subscript', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '214', 'type': 'integer', 'children': [], 'value': '1'},{'id': '215', 'type': 'comparison_operator', 'children': ['216', '220'], 'value': '>'},{'id': '216', 'type': 'call', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '220', 'type': 'integer', 'children': [], 'value': '1'},{'id': '221', 'type': 'None', 'children': []},{'id': '222', 'type': 'if_statement', 'children': ['223', '228']},{'id': '223', 'type': 'call', 'children': ['224', '225']},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '225', 'type': 'argument_list', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'top_most_item'},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'NameView'},{'id': '228', 'type': 'block', 'children': ['229', '233']},{'id': '229', 'type': 'expression_statement', 'children': ['230']},{'id': '230', 'type': 'assignment', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'state_v'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'second_top_most_item'},{'id': '233', 'type': 'if_statement', 'children': ['234', '249']},{'id': '234', 'type': 'boolean_operator', 'children': ['235', '242'], 'value': 'and'},{'id': '235', 'type': 'comparison_operator', 'children': ['236', '237'], 'value': 'not'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'state_v'},{'id': '237', 'type': 'attribute', 'children': ['238', '241']},{'id': '238', 'type': 'attribute', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'selected_items'},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '244'], 'value': 'not'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'top_most_item'},{'id': '244', 'type': 'attribute', 'children': ['245', '248']},{'id': '245', 'type': 'attribute', 'children': ['246', '247']},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '247', 'type': 'identifier', 'children': [], 'value': 'view'},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'selected_items'},{'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': 'items'},{'id': '253', 'type': 'subscript', 'children': ['254', '255']},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '255', 'type': 'slice', 'children': ['256', '257']},{'id': '256', 'type': 'integer', 'children': [], 'value': '1'},{'id': '257', 'type': 'colon', 'children': []},{'id': '258', 'type': 'return_statement', 'children': ['259']},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'items'}
def _filter_hovered_items(self, items, event): items = self._filter_library_state(items) if not items: return items top_most_item = items[0] second_top_most_item = items[1] if len(items) > 1 else None first_state_v = next(filter(lambda item: isinstance(item, (NameView, StateView)), items)) first_state_v = first_state_v.parent if isinstance(first_state_v, NameView) else first_state_v if first_state_v: for item in items: if isinstance(item, ConnectionView): if self.view.canvas.get_parent(top_most_item) is not first_state_v: continue break port_beneath_cursor = False state_ports = first_state_v.get_all_ports() position = self.view.get_matrix_v2i(first_state_v).transform_point(event.x, event.y) i2v_matrix = self.view.get_matrix_i2v(first_state_v) for port_v in state_ports: item_distance = port_v.port.glue(position)[1] view_distance = i2v_matrix.transform_distance(item_distance, 0)[0] if view_distance == 0: port_beneath_cursor = True break if port_beneath_cursor: items = self.dismiss_upper_items(items, item) top_most_item = items[0] second_top_most_item = items[1] if len(items) > 1 else None if isinstance(top_most_item, NameView): state_v = second_top_most_item if state_v not in self.view.selected_items and top_most_item not in self.view.selected_items: items = items[1:] return items
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'compare_variables'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'tree_model'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'iter1'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'iter2'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'user_data'},{'id': '9', 'type': 'None', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '22', '33', '41', '49', '68', '87']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'path1'},{'id': '14', 'type': 'subscript', 'children': ['15', '21']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'tree_model'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'get_path'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'iter1'},{'id': '21', 'type': 'integer', 'children': [], 'value': '0'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'path2'},{'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': 'tree_model'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'get_path'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'iter2'},{'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': 'name1'},{'id': '36', 'type': 'subscript', 'children': ['37', '40']},{'id': '37', 'type': 'subscript', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'tree_model'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'path1'},{'id': '40', 'type': 'integer', 'children': [], 'value': '0'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'name2'},{'id': '44', 'type': 'subscript', 'children': ['45', '48']},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'tree_model'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'path2'},{'id': '48', 'type': 'integer', 'children': [], 'value': '0'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'name1_as_bits'},{'id': '52', 'type': 'call', 'children': ['53', '56']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'string', 'children': [], 'value': "' '"},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '56', 'type': 'generator_expression', 'children': ['57', '65']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '59', 'type': 'argument_list', 'children': ['60', '64']},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'ord'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '64', 'type': 'string', 'children': [], 'value': "'b'"},{'id': '65', 'type': 'for_in_clause', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'name1'},{'id': '68', 'type': 'expression_statement', 'children': ['69']},{'id': '69', 'type': 'assignment', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'name2_as_bits'},{'id': '71', 'type': 'call', 'children': ['72', '75']},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'string', 'children': [], 'value': "' '"},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '75', 'type': 'generator_expression', 'children': ['76', '84']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '78', 'type': 'argument_list', 'children': ['79', '83']},{'id': '79', 'type': 'call', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'ord'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '83', 'type': 'string', 'children': [], 'value': "'b'"},{'id': '84', 'type': 'for_in_clause', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'name2'},{'id': '87', 'type': 'if_statement', 'children': ['88', '91', '94', '101']},{'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': '=='},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'name1_as_bits'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'name2_as_bits'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'return_statement', 'children': ['93']},{'id': '93', 'type': 'integer', 'children': [], 'value': '0'},{'id': '94', 'type': 'elif_clause', 'children': ['95', '98']},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': '>'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'name1_as_bits'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'name2_as_bits'},{'id': '98', 'type': 'block', 'children': ['99']},{'id': '99', 'type': 'return_statement', 'children': ['100']},{'id': '100', 'type': 'integer', 'children': [], 'value': '1'},{'id': '101', 'type': 'else_clause', 'children': ['102']},{'id': '102', 'type': 'block', 'children': ['103']},{'id': '103', 'type': 'return_statement', 'children': ['104']},{'id': '104', 'type': 'unary_operator', 'children': ['105'], 'value': '-'},{'id': '105', 'type': 'integer', 'children': [], 'value': '1'}
def compare_variables(tree_model, iter1, iter2, user_data=None): path1 = tree_model.get_path(iter1)[0] path2 = tree_model.get_path(iter2)[0] name1 = tree_model[path1][0] name2 = tree_model[path2][0] name1_as_bits = ' '.join(format(ord(x), 'b') for x in name1) name2_as_bits = ' '.join(format(ord(x), 'b') for x in name2) if name1_as_bits == name2_as_bits: return 0 elif name1_as_bits > name2_as_bits: return 1 else: return -1
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_hook_files'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'pathname'},{'id': '5', 'type': 'block', 'children': ['6', '8', '54']},{'id': '6', 'type': 'global_statement', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'hooks'},{'id': '8', 'type': 'if_statement', 'children': ['9', '24', '40']},{'id': '9', 'type': 'boolean_operator', 'children': ['10', '17'], 'value': 'and'},{'id': '10', 'type': 'comparison_operator', 'children': ['11', '16'], 'value': '>'},{'id': '11', 'type': 'subscript', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'version_info'},{'id': '15', 'type': 'integer', 'children': [], 'value': '0'},{'id': '16', 'type': 'integer', 'children': [], 'value': '2'},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '23'], 'value': '>'},{'id': '18', 'type': 'subscript', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'version_info'},{'id': '22', 'type': 'integer', 'children': [], 'value': '1'},{'id': '23', 'type': 'integer', 'children': [], 'value': '4'},{'id': '24', 'type': 'block', 'children': ['25']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'fsglob'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'call', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'iglob'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'pathname'},{'id': '37', 'type': 'keyword_argument', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'recursive'},{'id': '39', 'type': 'True', 'children': []},{'id': '40', 'type': 'else_clause', 'children': ['41']},{'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': 'fsglob'},{'id': '45', 'type': 'call', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'iglob'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'pathname'},{'id': '54', 'type': 'for_statement', 'children': ['55', '56', '57']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'fsglob'},{'id': '57', 'type': 'block', 'children': ['58', '69', '99', '116']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'real_path'},{'id': '61', 'type': 'call', 'children': ['62', '67']},{'id': '62', 'type': 'attribute', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'realpath'},{'id': '67', 'type': 'argument_list', 'children': ['68']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '69', 'type': 'if_statement', 'children': ['70', '82']},{'id': '70', 'type': 'comparison_operator', 'children': ['71', '79'], 'value': 'not'},{'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': 'os'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'real_path'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'call', 'children': ['85', '90']},{'id': '85', 'type': 'attribute', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sys'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'call', 'children': ['92', '97']},{'id': '92', 'type': 'attribute', 'children': ['93', '96']},{'id': '93', 'type': 'attribute', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'dirname'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'real_path'},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'imp'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'load_source'},{'id': '106', 'type': 'argument_list', 'children': ['107', '115']},{'id': '107', 'type': 'call', 'children': ['108', '113']},{'id': '108', 'type': 'attribute', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'os'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'basename'},{'id': '113', 'type': 'argument_list', 'children': ['114']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'real_path'},{'id': '116', 'type': 'for_statement', 'children': ['117', '118', '122']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '118', 'type': 'call', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'dir'},{'id': '120', 'type': 'argument_list', 'children': ['121']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '122', 'type': 'block', 'children': ['123', '131']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '126', 'type': 'call', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '128', 'type': 'argument_list', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '131', 'type': 'if_statement', 'children': ['132', '142']},{'id': '132', 'type': 'boolean_operator', 'children': ['133', '138'], 'value': 'and'},{'id': '133', 'type': 'call', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '135', 'type': 'argument_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '137', 'type': 'string', 'children': [], 'value': "'dredd_hooks'"},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'callable'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '142', 'type': 'block', 'children': ['143', '151']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '146']},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'func_hooks'},{'id': '146', 'type': 'call', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '148', 'type': 'argument_list', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '150', 'type': 'string', 'children': [], 'value': "'dredd_hooks'"},{'id': '151', 'type': 'for_statement', 'children': ['152', '155', '156']},{'id': '152', 'type': 'pattern_list', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'func_hooks'},{'id': '156', 'type': 'block', 'children': ['157', '171', '185', '199', '213', '227', '241', '255']},{'id': '157', 'type': 'if_statement', 'children': ['158', '161']},{'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': '=='},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'BEFORE_ALL'},{'id': '161', 'type': 'block', 'children': ['162']},{'id': '162', 'type': 'expression_statement', 'children': ['163']},{'id': '163', 'type': 'call', 'children': ['164', '169']},{'id': '164', 'type': 'attribute', 'children': ['165', '168']},{'id': '165', 'type': 'attribute', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'hooks'},{'id': '167', 'type': 'identifier', 'children': [], 'value': '_before_all'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '169', 'type': 'argument_list', 'children': ['170']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '171', 'type': 'if_statement', 'children': ['172', '175']},{'id': '172', 'type': 'comparison_operator', 'children': ['173', '174'], 'value': '=='},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'AFTER_ALL'},{'id': '175', 'type': 'block', 'children': ['176']},{'id': '176', 'type': 'expression_statement', 'children': ['177']},{'id': '177', 'type': 'call', 'children': ['178', '183']},{'id': '178', 'type': 'attribute', 'children': ['179', '182']},{'id': '179', 'type': 'attribute', 'children': ['180', '181']},{'id': '180', 'type': 'identifier', 'children': [], 'value': 'hooks'},{'id': '181', 'type': 'identifier', 'children': [], 'value': '_after_all'},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '183', 'type': 'argument_list', 'children': ['184']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '185', 'type': 'if_statement', 'children': ['186', '189']},{'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': '=='},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'BEFORE_EACH'},{'id': '189', 'type': 'block', 'children': ['190']},{'id': '190', 'type': 'expression_statement', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '197']},{'id': '192', 'type': 'attribute', 'children': ['193', '196']},{'id': '193', 'type': 'attribute', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'hooks'},{'id': '195', 'type': 'identifier', 'children': [], 'value': '_before_each'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '197', 'type': 'argument_list', 'children': ['198']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '199', 'type': 'if_statement', 'children': ['200', '203']},{'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': '=='},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '202', 'type': 'identifier', 'children': [], 'value': 'AFTER_EACH'},{'id': '203', 'type': 'block', 'children': ['204']},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'call', 'children': ['206', '211']},{'id': '206', 'type': 'attribute', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'hooks'},{'id': '209', 'type': 'identifier', 'children': [], 'value': '_after_each'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '211', 'type': 'argument_list', 'children': ['212']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '213', 'type': 'if_statement', 'children': ['214', '217']},{'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': '=='},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'BEFORE_EACH_VALIDATION'},{'id': '217', 'type': 'block', 'children': ['218']},{'id': '218', 'type': 'expression_statement', 'children': ['219']},{'id': '219', 'type': 'call', 'children': ['220', '225']},{'id': '220', 'type': 'attribute', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'hooks'},{'id': '223', 'type': 'identifier', 'children': [], 'value': '_before_each_validation'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '225', 'type': 'argument_list', 'children': ['226']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '227', 'type': 'if_statement', 'children': ['228', '231']},{'id': '228', 'type': 'comparison_operator', 'children': ['229', '230'], 'value': '=='},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'BEFORE_VALIDATION'},{'id': '231', 'type': 'block', 'children': ['232']},{'id': '232', 'type': 'expression_statement', 'children': ['233']},{'id': '233', 'type': 'call', 'children': ['234', '235']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'add_named_hook'},{'id': '235', 'type': 'argument_list', 'children': ['236', '239', '240']},{'id': '236', 'type': 'attribute', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'hooks'},{'id': '238', 'type': 'identifier', 'children': [], 'value': '_before_validation'},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '240', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '241', 'type': 'if_statement', 'children': ['242', '245']},{'id': '242', 'type': 'comparison_operator', 'children': ['243', '244'], 'value': '=='},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '244', 'type': 'identifier', 'children': [], 'value': 'BEFORE'},{'id': '245', 'type': 'block', 'children': ['246']},{'id': '246', 'type': 'expression_statement', 'children': ['247']},{'id': '247', 'type': 'call', 'children': ['248', '249']},{'id': '248', 'type': 'identifier', 'children': [], 'value': 'add_named_hook'},{'id': '249', 'type': 'argument_list', 'children': ['250', '253', '254']},{'id': '250', 'type': 'attribute', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'hooks'},{'id': '252', 'type': 'identifier', 'children': [], 'value': '_before'},{'id': '253', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '254', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '255', 'type': 'if_statement', 'children': ['256', '259']},{'id': '256', 'type': 'comparison_operator', 'children': ['257', '258'], 'value': '=='},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'hook'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'AFTER'},{'id': '259', 'type': 'block', 'children': ['260']},{'id': '260', 'type': 'expression_statement', 'children': ['261']},{'id': '261', 'type': 'call', 'children': ['262', '263']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'add_named_hook'},{'id': '263', 'type': 'argument_list', 'children': ['264', '267', '268']},{'id': '264', 'type': 'attribute', 'children': ['265', '266']},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'hooks'},{'id': '266', 'type': 'identifier', 'children': [], 'value': '_after'},{'id': '267', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '268', 'type': 'identifier', 'children': [], 'value': 'name'}
def load_hook_files(pathname): global hooks if sys.version_info[0] > 2 and sys.version_info[1] > 4: fsglob = sorted(glob.iglob(pathname, recursive=True)) else: fsglob = sorted(glob.iglob(pathname)) for path in fsglob: real_path = os.path.realpath(path) if os.path.dirname(real_path) not in sys.path: sys.path.append(os.path.dirname(real_path)) module = imp.load_source(os.path.basename(path), real_path) for name in dir(module): obj = getattr(module, name) if hasattr(obj, 'dredd_hooks') and callable(obj): func_hooks = getattr(obj, 'dredd_hooks') for hook, name in func_hooks: if hook == BEFORE_ALL: hooks._before_all.append(obj) if hook == AFTER_ALL: hooks._after_all.append(obj) if hook == BEFORE_EACH: hooks._before_each.append(obj) if hook == AFTER_EACH: hooks._after_each.append(obj) if hook == BEFORE_EACH_VALIDATION: hooks._before_each_validation.append(obj) if hook == BEFORE_VALIDATION: add_named_hook(hooks._before_validation, obj, name) if hook == BEFORE: add_named_hook(hooks._before, obj, name) if hook == AFTER: add_named_hook(hooks._after, obj, name)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'imports'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'separate'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'import_before_from'},{'id': '10', 'type': 'True', 'children': []},{'id': '11', 'type': 'dictionary_splat_pattern', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'classify_kwargs'},{'id': '13', 'type': 'block', 'children': ['14', '67', '101', '110', '126', '148']},{'id': '14', 'type': 'if_statement', 'children': ['15', '16', '39']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'separate'},{'id': '16', 'type': 'block', 'children': ['17', '33']},{'id': '17', 'type': 'function_definition', 'children': ['18', '19', '21']},{'id': '18', 'type': 'function_name', 'children': [], 'value': 'classify_func'},{'id': '19', 'type': 'parameters', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'classify_import'},{'id': '25', 'type': 'argument_list', 'children': ['26', '31']},{'id': '26', 'type': 'attribute', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'import_statement'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '31', 'type': 'dictionary_splat', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'classify_kwargs'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'ImportType'},{'id': '38', 'type': 'identifier', 'children': [], 'value': '__all__'},{'id': '39', 'type': 'else_clause', 'children': ['40']},{'id': '40', 'type': 'block', 'children': ['41', '61']},{'id': '41', 'type': 'function_definition', 'children': ['42', '43', '45']},{'id': '42', 'type': 'function_name', 'children': [], 'value': 'classify_func'},{'id': '43', 'type': 'parameters', 'children': ['44']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '45', 'type': 'block', 'children': ['46']},{'id': '46', 'type': 'return_statement', 'children': ['47']},{'id': '47', 'type': 'comparison_operator', 'children': ['48', '58'], 'value': '=='},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'classify_import'},{'id': '50', 'type': 'argument_list', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'import_statement'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'module'},{'id': '56', 'type': 'dictionary_splat', 'children': ['57']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'classify_kwargs'},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'ImportType'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'FUTURE'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '64', 'type': 'list', 'children': ['65', '66'], 'value': '[True, False]'},{'id': '65', 'type': 'True', 'children': []},{'id': '66', 'type': 'False', 'children': []},{'id': '67', 'type': 'if_statement', 'children': ['68', '69', '87']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'import_before_from'},{'id': '69', 'type': 'block', 'children': ['70']},{'id': '70', 'type': 'function_definition', 'children': ['71', '72', '74']},{'id': '71', 'type': 'function_name', 'children': [], 'value': 'sort_within'},{'id': '72', 'type': 'parameters', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '74', 'type': 'block', 'children': ['75']},{'id': '75', 'type': 'return_statement', 'children': ['76']},{'id': '76', 'type': 'binary_operator', 'children': ['77', '84'], 'value': '+'},{'id': '77', 'type': 'tuple', 'children': ['78']},{'id': '78', 'type': 'subscript', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'CLS_TO_INDEX'},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '84', 'type': 'attribute', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '87', 'type': 'else_clause', 'children': ['88']},{'id': '88', 'type': 'block', 'children': ['89']},{'id': '89', 'type': 'function_definition', 'children': ['90', '91', '93']},{'id': '90', 'type': 'function_name', 'children': [], 'value': 'sort_within'},{'id': '91', 'type': 'parameters', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'obj'},{'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': 'tuple'},{'id': '97', 'type': 'argument_list', 'children': ['98']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'sort_key'},{'id': '101', 'type': 'expression_statement', 'children': ['102']},{'id': '102', 'type': 'assignment', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'imports_partitioned'},{'id': '104', 'type': 'call', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'defaultdict'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '110', 'type': 'for_statement', 'children': ['111', '112', '113']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'import_obj'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'imports'},{'id': '113', 'type': 'block', 'children': ['114']},{'id': '114', 'type': 'expression_statement', 'children': ['115']},{'id': '115', 'type': 'call', 'children': ['116', '124']},{'id': '116', 'type': 'attribute', 'children': ['117', '123']},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'imports_partitioned'},{'id': '119', 'type': 'call', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'classify_func'},{'id': '121', 'type': 'argument_list', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'import_obj'},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'import_obj'},{'id': '126', 'type': 'for_statement', 'children': ['127', '130', '135']},{'id': '127', 'type': 'pattern_list', 'children': ['128', '129']},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'segment_key'},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '130', 'type': 'call', 'children': ['131', '134']},{'id': '131', 'type': 'attribute', 'children': ['132', '133']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'imports_partitioned'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '134', 'type': 'argument_list', 'children': []},{'id': '135', 'type': 'block', 'children': ['136']},{'id': '136', 'type': 'expression_statement', 'children': ['137']},{'id': '137', 'type': 'assignment', 'children': ['138', '141']},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'imports_partitioned'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'segment_key'},{'id': '141', 'type': 'call', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '143', 'type': 'argument_list', 'children': ['144', '145']},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '145', 'type': 'keyword_argument', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'sort_within'},{'id': '148', 'type': 'return_statement', 'children': ['149']},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '151', 'type': 'generator_expression', 'children': ['152', '158', '161']},{'id': '152', 'type': 'call', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'tuple'},{'id': '154', 'type': 'argument_list', 'children': ['155']},{'id': '155', 'type': 'subscript', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'imports_partitioned'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '158', 'type': 'for_in_clause', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'types'},{'id': '161', 'type': 'if_clause', 'children': ['162']},{'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': 'in'},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'imports_partitioned'}
def sort(imports, separate=True, import_before_from=True, **classify_kwargs): if separate: def classify_func(obj): return classify_import( obj.import_statement.module, **classify_kwargs ) types = ImportType.__all__ else: def classify_func(obj): return classify_import( obj.import_statement.module, **classify_kwargs ) == ImportType.FUTURE types = [True, False] if import_before_from: def sort_within(obj): return (CLS_TO_INDEX[type(obj)],) + obj.sort_key else: def sort_within(obj): return tuple(obj.sort_key) imports_partitioned = collections.defaultdict(list) for import_obj in imports: imports_partitioned[classify_func(import_obj)].append(import_obj) for segment_key, val in imports_partitioned.items(): imports_partitioned[segment_key] = sorted(val, key=sort_within) return tuple( tuple(imports_partitioned[key]) for key in types if key in imports_partitioned )
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_recursive'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'block', 'children': ['6', '10', '53']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'newdict'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '17']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '16', 'type': 'argument_list', 'children': []},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'if_statement', 'children': ['19', '27', '41']},{'id': '19', 'type': 'comparison_operator', 'children': ['20', '26'], 'value': 'is'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'subscript', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '25', 'type': 'integer', 'children': [], 'value': '1'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '35']},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'newdict'},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '34', 'type': 'integer', 'children': [], 'value': '0'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort_recursive'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'subscript', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'else_clause', 'children': ['42']},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '50']},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'newdict'},{'id': '47', 'type': 'subscript', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '49', 'type': 'integer', 'children': [], 'value': '0'},{'id': '50', 'type': 'subscript', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'},{'id': '53', 'type': 'return_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '59', 'type': 'argument_list', 'children': ['60', '65']},{'id': '60', 'type': 'call', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'newdict'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '64', 'type': 'argument_list', 'children': []},{'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '67', 'type': 'lambda', 'children': ['68', '70']},{'id': '68', 'type': 'lambda_parameters', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '70', 'type': 'tuple', 'children': ['71', '80']},{'id': '71', 'type': 'call', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'compare_type'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'subscript', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '79', 'type': 'integer', 'children': [], 'value': '1'},{'id': '80', 'type': 'subscript', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '82', 'type': 'integer', 'children': [], 'value': '0'}
def sort_recursive(data): newdict = {} for i in data.items(): if type(i[1]) is dict: newdict[i[0]] = sort_recursive(i[1]) else: newdict[i[0]] = i[1] return OrderedDict(sorted(newdict.items(), key=lambda item: (compare_type(type(item[1])), item[0])))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'names_to_abbreviations'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'reporters'},{'id': '5', 'type': 'block', 'children': ['6', '10', '70', '92']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '9', 'type': 'dictionary', 'children': []},{'id': '10', 'type': 'for_statement', 'children': ['11', '14', '19']},{'id': '11', 'type': 'pattern_list', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'reporter_key'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'data_list'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'reporters'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'data_list'},{'id': '23', 'type': 'block', 'children': ['24', '34', '52', '62']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'abbrevs'},{'id': '27', 'type': 'call', 'children': ['28', '33']},{'id': '28', 'type': 'attribute', 'children': ['29', '32']},{'id': '29', 'type': 'subscript', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '31', 'type': 'string', 'children': [], 'value': "'editions'"},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '33', 'type': 'argument_list', 'children': []},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sort_func'},{'id': '37', 'type': 'lambda', 'children': ['38', '40']},{'id': '38', 'type': 'lambda_parameters', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '40', 'type': 'binary_operator', 'children': ['41', '51'], 'value': '+'},{'id': '41', 'type': 'call', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '43', 'type': 'argument_list', 'children': ['44']},{'id': '44', 'type': 'subscript', 'children': ['45', '50']},{'id': '45', 'type': 'subscript', 'children': ['46', '49']},{'id': '46', 'type': 'subscript', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '48', 'type': 'string', 'children': [], 'value': "'editions'"},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '50', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'abbrevs'},{'id': '55', 'type': 'call', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'abbrevs'},{'id': '59', 'type': 'keyword_argument', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sort_func'},{'id': '62', 'type': 'expression_statement', 'children': ['63']},{'id': '63', 'type': 'assignment', 'children': ['64', '69']},{'id': '64', 'type': 'subscript', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '68', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'abbrevs'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'sorted_names'},{'id': '73', 'type': 'call', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '78', 'type': 'argument_list', 'children': ['79', '84']},{'id': '79', 'type': 'call', 'children': ['80', '83']},{'id': '80', 'type': 'attribute', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'names'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '83', 'type': 'argument_list', 'children': []},{'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '86', 'type': 'lambda', 'children': ['87', '89']},{'id': '87', 'type': 'lambda_parameters', 'children': ['88']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '89', 'type': 'subscript', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 't'},{'id': '91', 'type': 'integer', 'children': [], 'value': '0'},{'id': '92', 'type': 'return_statement', 'children': ['93']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'sorted_names'}
def names_to_abbreviations(reporters): names = {} for reporter_key, data_list in reporters.items(): for data in data_list: abbrevs = data['editions'].keys() sort_func = lambda x: str(data['editions'][x]['start']) + x abbrevs = sorted(abbrevs, key=sort_func) names[data['name']] = abbrevs sorted_names = OrderedDict(sorted(names.items(), key=lambda t: t[0])) return sorted_names
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'flatten'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '5', 'type': 'block', 'children': ['6', '126']},{'id': '6', 'type': 'if_statement', 'children': ['7', '14', '37', '119']},{'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': 'weights'},{'id': '11', 'type': 'attribute', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'DataFrame'},{'id': '14', 'type': 'block', 'children': ['15', '27']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'wts'},{'id': '18', 'type': 'call', 'children': ['19', '26']},{'id': '19', 'type': 'attribute', 'children': ['20', '25']},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'reset_index'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'wts'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '32', 'type': 'list', 'children': ['33', '34', '35', '36'], 'value': '["date", "contract", "generic", "weight"]'},{'id': '33', 'type': 'string', 'children': [], 'value': '"date"'},{'id': '34', 'type': 'string', 'children': [], 'value': '"contract"'},{'id': '35', 'type': 'string', 'children': [], 'value': '"generic"'},{'id': '36', 'type': 'string', 'children': [], 'value': '"weight"'},{'id': '37', 'type': 'elif_clause', 'children': ['38', '43']},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '40', 'type': 'argument_list', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '43', 'type': 'block', 'children': ['44', '48', '100']},{'id': '44', 'type': 'expression_statement', 'children': ['45']},{'id': '45', 'type': 'assignment', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'wts'},{'id': '47', 'type': 'list', 'children': [], 'value': '[]'},{'id': '48', 'type': 'for_statement', 'children': ['49', '50', '58']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'call', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '57', 'type': 'argument_list', 'children': []},{'id': '58', 'type': 'block', 'children': ['59', '73', '83', '93']},{'id': '59', 'type': 'expression_statement', 'children': ['60']},{'id': '60', 'type': 'assignment', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '62', 'type': 'call', 'children': ['63', '72']},{'id': '63', 'type': 'attribute', 'children': ['64', '71']},{'id': '64', 'type': 'call', 'children': ['65', '70']},{'id': '65', 'type': 'attribute', 'children': ['66', '69']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'stack'},{'id': '70', 'type': 'argument_list', 'children': []},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'reset_index'},{'id': '72', 'type': 'argument_list', 'children': []},{'id': '73', 'type': 'expression_statement', 'children': ['74']},{'id': '74', 'type': 'assignment', 'children': ['75', '78']},{'id': '75', 'type': 'attribute', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '78', 'type': 'list', 'children': ['79', '80', '81', '82'], 'value': '["date", "contract", "generic", "weight"]'},{'id': '79', 'type': 'string', 'children': [], 'value': '"date"'},{'id': '80', 'type': 'string', 'children': [], 'value': '"contract"'},{'id': '81', 'type': 'string', 'children': [], 'value': '"generic"'},{'id': '82', 'type': 'string', 'children': [], 'value': '"weight"'},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'assignment', 'children': ['85', '92']},{'id': '85', 'type': 'subscript', 'children': ['86', '89', '91']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '89', 'type': 'slice', 'children': ['90']},{'id': '90', 'type': 'colon', 'children': []},{'id': '91', 'type': 'string', 'children': [], 'value': '"key"'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'wts'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'wt'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'wts'},{'id': '103', 'type': 'call', 'children': ['104', '115']},{'id': '104', 'type': 'attribute', 'children': ['105', '114']},{'id': '105', 'type': 'call', 'children': ['106', '109']},{'id': '106', 'type': 'attribute', 'children': ['107', '108']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '109', 'type': 'argument_list', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'wts'},{'id': '111', 'type': 'keyword_argument', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '113', 'type': 'integer', 'children': [], 'value': '0'},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'reset_index'},{'id': '115', 'type': 'argument_list', 'children': ['116']},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'drop'},{'id': '118', 'type': 'True', 'children': []},{'id': '119', 'type': 'else_clause', 'children': ['120']},{'id': '120', 'type': 'block', 'children': ['121']},{'id': '121', 'type': 'raise_statement', 'children': ['122']},{'id': '122', 'type': 'call', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '124', 'type': 'argument_list', 'children': ['125']},{'id': '125', 'type': 'string', 'children': [], 'value': '"weights must be pd.DataFrame or dict"'},{'id': '126', 'type': 'return_statement', 'children': ['127']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'wts'}
def flatten(weights): if isinstance(weights, pd.DataFrame): wts = weights.stack().reset_index() wts.columns = ["date", "contract", "generic", "weight"] elif isinstance(weights, dict): wts = [] for key in sorted(weights.keys()): wt = weights[key].stack().reset_index() wt.columns = ["date", "contract", "generic", "weight"] wt.loc[:, "key"] = key wts.append(wt) wts = pd.concat(wts, axis=0).reset_index(drop=True) else: raise ValueError("weights must be pd.DataFrame or dict") return wts
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'calc_trades'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'current_contracts'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'desired_holdings'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'trade_weights'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'prices'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'multipliers'},{'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '11', 'type': 'block', 'children': ['12', '27', '31', '46', '86', '90', '191', '203', '215', '225', '233']},{'id': '12', 'type': 'if_statement', 'children': ['13', '19']},{'id': '13', 'type': 'not_operator', 'children': ['14']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'trade_weights'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '19', 'type': 'block', 'children': ['20']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'trade_weights'},{'id': '23', 'type': 'dictionary', 'children': ['24']},{'id': '24', 'type': 'pair', 'children': ['25', '26']},{'id': '25', 'type': 'string', 'children': [], 'value': '""'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'trade_weights'},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'generics'},{'id': '30', 'type': 'list', 'children': [], 'value': '[]'},{'id': '31', 'type': 'for_statement', 'children': ['32', '33', '34']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'trade_weights'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'call', 'children': ['37', '40']},{'id': '37', 'type': 'attribute', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'generics'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'trade_weights'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '46', 'type': 'if_statement', 'children': ['47', '62']},{'id': '47', 'type': 'not_operator', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '57']},{'id': '49', 'type': 'attribute', 'children': ['50', '56']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'desired_holdings'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '57', 'type': 'argument_list', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'generics'},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'raise_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '75']},{'id': '68', 'type': 'attribute', 'children': ['69', '74']},{'id': '69', 'type': 'concatenated_string', 'children': ['70', '71', '72', '73']},{'id': '70', 'type': 'string', 'children': [], 'value': '"\'desired_holdings.index\' contains values which "'},{'id': '71', 'type': 'string', 'children': [], 'value': '"cannot be mapped to tradeables.\\n"'},{'id': '72', 'type': 'string', 'children': [], 'value': '"Received: \'desired_holdings.index\'\\n {0}\\n"'},{'id': '73', 'type': 'string', 'children': [], 'value': '"Expected in \'trade_weights\' set of columns:\\n {1}\\n"'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '75', 'type': 'argument_list', 'children': ['76', '82']},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'desired_holdings'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'generics'},{'id': '86', 'type': 'expression_statement', 'children': ['87']},{'id': '87', 'type': 'assignment', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'desired_contracts'},{'id': '89', 'type': 'list', 'children': [], 'value': '[]'},{'id': '90', 'type': 'for_statement', 'children': ['91', '92', '93']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'root_key'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'trade_weights'},{'id': '93', 'type': 'block', 'children': ['94', '100', '113', '121', '131', '150', '156', '167', '177']},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'gnrc_weights'},{'id': '97', 'type': 'subscript', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'trade_weights'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'root_key'},{'id': '100', 'type': 'expression_statement', 'children': ['101']},{'id': '101', 'type': 'assignment', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'subset'},{'id': '103', 'type': 'call', 'children': ['104', '109']},{'id': '104', 'type': 'attribute', 'children': ['105', '108']},{'id': '105', 'type': 'attribute', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'gnrc_weights'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'columns'},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '109', 'type': 'argument_list', 'children': ['110']},{'id': '110', 'type': 'attribute', 'children': ['111', '112']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'desired_holdings'},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '113', 'type': 'expression_statement', 'children': ['114']},{'id': '114', 'type': 'assignment', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'gnrc_des_hlds'},{'id': '116', 'type': 'subscript', 'children': ['117', '120']},{'id': '117', 'type': 'attribute', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'desired_holdings'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'subset'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'gnrc_weights'},{'id': '124', 'type': 'subscript', 'children': ['125', '128', '130']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'gnrc_weights'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '128', 'type': 'slice', 'children': ['129']},{'id': '129', 'type': 'colon', 'children': []},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'subset'},{'id': '131', 'type': 'expression_statement', 'children': ['132']},{'id': '132', 'type': 'assignment', 'children': ['133', '134']},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'gnrc_weights'},{'id': '134', 'type': 'subscript', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'gnrc_weights'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '138', 'type': 'unary_operator', 'children': ['139'], 'value': '~'},{'id': '139', 'type': 'call', 'children': ['140', '146']},{'id': '140', 'type': 'attribute', 'children': ['141', '145']},{'id': '141', 'type': '()', 'children': ['142']},{'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '=='},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'gnrc_weights'},{'id': '144', 'type': 'integer', 'children': [], 'value': '0'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '146', 'type': 'argument_list', 'children': ['147']},{'id': '147', 'type': 'keyword_argument', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '149', 'type': 'integer', 'children': [], 'value': '1'},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'assignment', 'children': ['152', '153']},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'instr_des_hlds'},{'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '*'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'gnrc_des_hlds'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'gnrc_weights'},{'id': '156', 'type': 'expression_statement', 'children': ['157']},{'id': '157', 'type': 'assignment', 'children': ['158', '159']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'instr_des_hlds'},{'id': '159', 'type': 'call', 'children': ['160', '163']},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'instr_des_hlds'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '163', 'type': 'argument_list', 'children': ['164']},{'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '166', 'type': 'integer', 'children': [], 'value': '1'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'wprices'},{'id': '170', 'type': 'subscript', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'prices'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '174', 'type': 'attribute', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'instr_des_hlds'},{'id': '176', 'type': 'identifier', 'children': [], 'value': 'index'},{'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': 'desired_contracts'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '182', 'type': 'argument_list', 'children': ['183']},{'id': '183', 'type': 'call', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'to_contracts'},{'id': '185', 'type': 'argument_list', 'children': ['186', '187', '188', '189']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'instr_des_hlds'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'wprices'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'multipliers'},{'id': '189', 'type': 'dictionary_splat', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '191', 'type': 'expression_statement', 'children': ['192']},{'id': '192', 'type': 'assignment', 'children': ['193', '194']},{'id': '193', 'type': 'identifier', 'children': [], 'value': 'desired_contracts'},{'id': '194', 'type': 'call', 'children': ['195', '198']},{'id': '195', 'type': 'attribute', 'children': ['196', '197']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'concat'},{'id': '198', 'type': 'argument_list', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'desired_contracts'},{'id': '200', 'type': 'keyword_argument', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'axis'},{'id': '202', 'type': 'integer', 'children': [], 'value': '0'},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'trades'},{'id': '206', 'type': 'call', 'children': ['207', '210']},{'id': '207', 'type': 'attribute', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'desired_contracts'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'subtract'},{'id': '210', 'type': 'argument_list', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'current_contracts'},{'id': '212', 'type': 'keyword_argument', 'children': ['213', '214']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'fill_value'},{'id': '214', 'type': 'integer', 'children': [], 'value': '0'},{'id': '215', 'type': 'expression_statement', 'children': ['216']},{'id': '216', 'type': 'assignment', 'children': ['217', '218']},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'trades'},{'id': '218', 'type': 'subscript', 'children': ['219', '222']},{'id': '219', 'type': 'attribute', 'children': ['220', '221']},{'id': '220', 'type': 'identifier', 'children': [], 'value': 'trades'},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'loc'},{'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': '!='},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'trades'},{'id': '224', 'type': 'integer', 'children': [], 'value': '0'},{'id': '225', 'type': 'expression_statement', 'children': ['226']},{'id': '226', 'type': 'assignment', 'children': ['227', '228']},{'id': '227', 'type': 'identifier', 'children': [], 'value': 'trades'},{'id': '228', 'type': 'call', 'children': ['229', '232']},{'id': '229', 'type': 'attribute', 'children': ['230', '231']},{'id': '230', 'type': 'identifier', 'children': [], 'value': 'trades'},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '232', 'type': 'argument_list', 'children': []},{'id': '233', 'type': 'return_statement', 'children': ['234']},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'trades'}
def calc_trades(current_contracts, desired_holdings, trade_weights, prices, multipliers, **kwargs): if not isinstance(trade_weights, dict): trade_weights = {"": trade_weights} generics = [] for key in trade_weights: generics.extend(trade_weights[key].columns) if not set(desired_holdings.index).issubset(set(generics)): raise ValueError("'desired_holdings.index' contains values which " "cannot be mapped to tradeables.\n" "Received: 'desired_holdings.index'\n {0}\n" "Expected in 'trade_weights' set of columns:\n {1}\n" .format(sorted(desired_holdings.index), sorted(generics))) desired_contracts = [] for root_key in trade_weights: gnrc_weights = trade_weights[root_key] subset = gnrc_weights.columns.intersection(desired_holdings.index) gnrc_des_hlds = desired_holdings.loc[subset] gnrc_weights = gnrc_weights.loc[:, subset] gnrc_weights = gnrc_weights.loc[~(gnrc_weights == 0).all(axis=1)] instr_des_hlds = gnrc_des_hlds * gnrc_weights instr_des_hlds = instr_des_hlds.sum(axis=1) wprices = prices.loc[instr_des_hlds.index] desired_contracts.append(to_contracts(instr_des_hlds, wprices, multipliers, **kwargs)) desired_contracts = pd.concat(desired_contracts, axis=0) trades = desired_contracts.subtract(current_contracts, fill_value=0) trades = trades.loc[trades != 0] trades = trades.sort_index() return trades
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_multiplier'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'root_generic_multiplier'},{'id': '6', 'type': 'block', 'children': ['7', '29', '33', '37', '93', '103', '111']},{'id': '7', 'type': 'if_statement', 'children': ['8', '21']},{'id': '8', 'type': 'boolean_operator', 'children': ['9', '15'], 'value': 'and'},{'id': '9', 'type': 'comparison_operator', 'children': ['10', '14'], 'value': '>'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'root_generic_multiplier'},{'id': '14', 'type': 'integer', 'children': [], 'value': '1'},{'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': 'weights'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'raise_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'concatenated_string', 'children': ['27', '28']},{'id': '27', 'type': 'string', 'children': [], 'value': '"For multiple generic instruments weights must be a "'},{'id': '28', 'type': 'string', 'children': [], 'value': '"dictionary"'},{'id': '29', 'type': 'expression_statement', 'children': ['30']},{'id': '30', 'type': 'assignment', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'mults'},{'id': '32', 'type': 'list', 'children': [], 'value': '[]'},{'id': '33', 'type': 'expression_statement', 'children': ['34']},{'id': '34', 'type': 'assignment', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'intrs'},{'id': '36', 'type': 'list', 'children': [], 'value': '[]'},{'id': '37', 'type': 'for_statement', 'children': ['38', '41', '46']},{'id': '38', 'type': 'pattern_list', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'ast'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'multiplier'},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'root_generic_multiplier'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'block', 'children': ['47', '70', '86']},{'id': '47', 'type': 'if_statement', 'children': ['48', '53', '62']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'isinstance'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'dict'},{'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': 'weights_ast'},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'subscript', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ast'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '62', 'type': 'else_clause', 'children': ['63']},{'id': '63', 'type': 'block', 'children': ['64']},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'weights_ast'},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'index'},{'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': 'mults'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '75', 'type': 'argument_list', 'children': ['76']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'multiplier'},{'id': '82', 'type': 'call', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '84', 'type': 'argument_list', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'weights_ast'},{'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': 'intrs'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '91', 'type': 'argument_list', 'children': ['92']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'weights_ast'},{'id': '93', 'type': 'expression_statement', 'children': ['94']},{'id': '94', 'type': 'assignment', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'imults'},{'id': '96', 'type': 'call', 'children': ['97', '100']},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'pd'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'Series'},{'id': '100', 'type': 'argument_list', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'mults'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'intrs'},{'id': '103', 'type': 'expression_statement', 'children': ['104']},{'id': '104', 'type': 'assignment', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'imults'},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'imults'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'sort_index'},{'id': '110', 'type': 'argument_list', 'children': []},{'id': '111', 'type': 'return_statement', 'children': ['112']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'imults'}
def get_multiplier(weights, root_generic_multiplier): if len(root_generic_multiplier) > 1 and not isinstance(weights, dict): raise ValueError("For multiple generic instruments weights must be a " "dictionary") mults = [] intrs = [] for ast, multiplier in root_generic_multiplier.iteritems(): if isinstance(weights, dict): weights_ast = weights[ast].index else: weights_ast = weights.index mults.extend(np.repeat(multiplier, len(weights_ast))) intrs.extend(weights_ast) imults = pd.Series(mults, intrs) imults = imults.sort_index() return imults
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'roller'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'timestamps'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'contract_dates'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'get_weights'},{'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '9', 'type': 'block', 'children': ['10', '17', '25', '30', '34', '38', '44', '60', '64', '88', '95']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'timestamps'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'timestamps'},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'contract_dates'},{'id': '20', 'type': 'call', 'children': ['21', '24']},{'id': '21', 'type': 'attribute', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'contract_dates'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'sort_values'},{'id': '24', 'type': 'argument_list', 'children': []},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'call', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_check_contract_dates'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'contract_dates'},{'id': '30', 'type': 'expression_statement', 'children': ['31']},{'id': '31', 'type': 'assignment', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '33', 'type': 'list', 'children': [], 'value': '[]'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'validate_inputs'},{'id': '37', 'type': 'True', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'timestamps'},{'id': '43', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'weights'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'get_weights'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54', '55', '58']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'contract_dates'},{'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'validate_inputs'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'validate_inputs'},{'id': '58', 'type': 'dictionary_splat', 'children': ['59']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'validate_inputs'},{'id': '63', 'type': 'False', 'children': []},{'id': '64', 'type': 'for_statement', 'children': ['65', '66', '71']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'timestamps'},{'id': '68', 'type': 'slice', 'children': ['69', '70']},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'colon', 'children': []},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'get_weights'},{'id': '80', 'type': 'argument_list', 'children': ['81', '82', '83', '86']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ts'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'contract_dates'},{'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'validate_inputs'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'validate_inputs'},{'id': '86', 'type': 'dictionary_splat', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'aggregate_weights'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'weights'},{'id': '95', 'type': 'return_statement', 'children': ['96']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'weights'}
def roller(timestamps, contract_dates, get_weights, **kwargs): timestamps = sorted(timestamps) contract_dates = contract_dates.sort_values() _check_contract_dates(contract_dates) weights = [] validate_inputs = True ts = timestamps[0] weights.extend(get_weights(ts, contract_dates, validate_inputs=validate_inputs, **kwargs)) validate_inputs = False for ts in timestamps[1:]: weights.extend(get_weights(ts, contract_dates, validate_inputs=validate_inputs, **kwargs)) weights = aggregate_weights(weights) return weights
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'strictly_monotonic'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'bb'},{'id': '5', 'type': 'block', 'children': ['6', '8', '21', '27', '42', '53', '65']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'string', 'children': [], 'value': "'''\n bb is an index array which may have numerous double or triple\n occurrences of indices, such as for example the decay_index_pointer.\n This method removes all entries <= -, then all dublicates and\n finally returns a sorted list of indices.\n '''"},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '11', 'type': 'subscript', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'bb'},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'where'},{'id': '17', 'type': 'argument_list', 'children': ['18']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': '>='},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'bb'},{'id': '20', 'type': 'integer', 'children': [], 'value': '0'},{'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': 'cc'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '30', 'type': 'binary_operator', 'children': ['31', '36'], 'value': '-'},{'id': '31', 'type': 'subscript', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '33', 'type': 'slice', 'children': ['34', '35']},{'id': '34', 'type': 'integer', 'children': [], 'value': '1'},{'id': '35', 'type': 'colon', 'children': []},{'id': '36', 'type': 'subscript', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '38', 'type': 'slice', 'children': ['39', '40']},{'id': '39', 'type': 'colon', 'children': []},{'id': '40', 'type': 'unary_operator', 'children': ['41'], 'value': '-'},{'id': '41', 'type': 'integer', 'children': [], 'value': '1'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '49', 'type': 'argument_list', 'children': ['50', '51', '52']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '51', 'type': 'integer', 'children': [], 'value': '0'},{'id': '52', 'type': 'integer', 'children': [], 'value': '1'},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'assignment', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'dc_mask'},{'id': '56', 'type': 'call', 'children': ['57', '62']},{'id': '57', 'type': 'attribute', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'ma'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'masked_equal'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'dc'},{'id': '64', 'type': 'integer', 'children': [], 'value': '0'},{'id': '65', 'type': 'return_statement', 'children': ['66']},{'id': '66', 'type': 'call', 'children': ['67', '82']},{'id': '67', 'type': 'attribute', 'children': ['68', '81']},{'id': '68', 'type': 'call', 'children': ['69', '74']},{'id': '69', 'type': 'attribute', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'ma'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'cc'},{'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'dc_mask'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'mask'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'compressed'},{'id': '82', 'type': 'argument_list', 'children': []}
def strictly_monotonic(bb): ''' bb is an index array which may have numerous double or triple occurrences of indices, such as for example the decay_index_pointer. This method removes all entries <= -, then all dublicates and finally returns a sorted list of indices. ''' cc=bb[np.where(bb>=0)] cc.sort() dc=cc[1:]-cc[:-1] dc=np.insert(dc,0,1) dc_mask=np.ma.masked_equal(dc,0) return np.ma.array(cc,mask=dc_mask.mask).compressed()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sort_shared_logical_disks'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'logical_disks'},{'id': '5', 'type': 'block', 'children': ['6', '24', '45', '49', '53', '75', '79', '83', '106', '119', '123', '203', '212']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'is_shared'},{'id': '9', 'type': '()', 'children': ['10']},{'id': '10', 'type': 'lambda', 'children': ['11', '13']},{'id': '11', 'type': 'lambda_parameters', 'children': ['12']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '13', 'type': 'conditional_expression', 'children': ['14', '15', '23'], 'value': 'if'},{'id': '14', 'type': 'True', 'children': []},{'id': '15', 'type': '()', 'children': ['16']},{'id': '16', 'type': 'boolean_operator', 'children': ['17', '20'], 'value': 'and'},{'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'in'},{'id': '18', 'type': 'string', 'children': [], 'value': "'share_physical_disks'"},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '20', 'type': 'subscript', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '22', 'type': 'string', 'children': [], 'value': "'share_physical_disks'"},{'id': '23', 'type': 'False', 'children': []},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'num_of_disks'},{'id': '27', 'type': '()', 'children': ['28']},{'id': '28', 'type': 'lambda', 'children': ['29', '31']},{'id': '29', 'type': 'lambda_parameters', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '31', 'type': 'conditional_expression', 'children': ['32', '35', '38'], 'value': 'if'},{'id': '32', 'type': 'subscript', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '34', 'type': 'string', 'children': [], 'value': "'number_of_physical_disks'"},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'in'},{'id': '36', 'type': 'string', 'children': [], 'value': "'number_of_physical_disks'"},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '38', 'type': 'subscript', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'constants'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'RAID_LEVEL_MIN_DISKS'},{'id': '42', 'type': 'subscript', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '44', 'type': 'string', 'children': [], 'value': "'raid_level'"},{'id': '45', 'type': 'expression_statement', 'children': ['46']},{'id': '46', 'type': 'assignment', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'logical_disks_shared'},{'id': '48', 'type': 'list', 'children': [], 'value': '[]'},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'logical_disks_nonshared'},{'id': '52', 'type': 'list', 'children': [], 'value': '[]'},{'id': '53', 'type': 'for_statement', 'children': ['54', '55', '56']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'logical_disks'},{'id': '56', 'type': 'block', 'children': ['57', '68']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'assignment', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '60', 'type': '()', 'children': ['61']},{'id': '61', 'type': 'conditional_expression', 'children': ['62', '63', '67'], 'value': 'if'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'logical_disks_shared'},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'is_shared'},{'id': '65', 'type': 'argument_list', 'children': ['66']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'logical_disks_nonshared'},{'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': 'target'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'logical_disks_shared_raid1'},{'id': '78', 'type': 'list', 'children': [], 'value': '[]'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'assignment', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'logical_disks_shared_excl_raid1'},{'id': '82', 'type': 'list', 'children': [], 'value': '[]'},{'id': '83', 'type': 'for_statement', 'children': ['84', '85', '86']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'logical_disks_shared'},{'id': '86', 'type': 'block', 'children': ['87', '99']},{'id': '87', 'type': 'expression_statement', 'children': ['88']},{'id': '88', 'type': 'assignment', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '90', 'type': '()', 'children': ['91']},{'id': '91', 'type': 'conditional_expression', 'children': ['92', '93', '98'], 'value': 'if'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'logical_disks_shared_raid1'},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '97'], 'value': '=='},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '96', 'type': 'string', 'children': [], 'value': "'raid_level'"},{'id': '97', 'type': 'string', 'children': [], 'value': "'1'"},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'logical_disks_shared_excl_raid1'},{'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': 'target'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'append'},{'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': 'logical_disks_shared'},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '111', 'type': 'argument_list', 'children': ['112', '113', '116']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'logical_disks_shared_excl_raid1'},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '115', 'type': 'True', 'children': []},{'id': '116', 'type': 'keyword_argument', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'num_of_disks'},{'id': '119', 'type': 'expression_statement', 'children': ['120']},{'id': '120', 'type': 'assignment', 'children': ['121', '122']},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '122', 'type': 'True', 'children': []},{'id': '123', 'type': 'for_statement', 'children': ['124', '125', '126']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'logical_disks_shared'},{'id': '126', 'type': 'block', 'children': ['127', '180']},{'id': '127', 'type': 'if_statement', 'children': ['128', '133']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '132'], 'value': '=='},{'id': '129', 'type': 'subscript', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '131', 'type': 'string', 'children': [], 'value': "'raid_level'"},{'id': '132', 'type': 'string', 'children': [], 'value': '"1+0"'},{'id': '133', 'type': 'block', 'children': ['134', '141']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'x_num'},{'id': '137', 'type': 'call', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'num_of_disks'},{'id': '139', 'type': 'argument_list', 'children': ['140']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '141', 'type': 'for_statement', 'children': ['142', '143', '144']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'logical_disks_shared'},{'id': '144', 'type': 'block', 'children': ['145']},{'id': '145', 'type': 'if_statement', 'children': ['146', '151']},{'id': '146', 'type': 'comparison_operator', 'children': ['147', '150'], 'value': '!='},{'id': '147', 'type': 'subscript', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '149', 'type': 'string', 'children': [], 'value': "'raid_level'"},{'id': '150', 'type': 'string', 'children': [], 'value': '"1+0"'},{'id': '151', 'type': 'block', 'children': ['152', '159']},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'y_num'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'num_of_disks'},{'id': '157', 'type': 'argument_list', 'children': ['158']},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '159', 'type': 'if_statement', 'children': ['160', '163']},{'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': '<'},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'x_num'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'y_num'},{'id': '163', 'type': 'block', 'children': ['164', '176']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'assignment', 'children': ['166', '167']},{'id': '166', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '167', 'type': '()', 'children': ['168']},{'id': '168', 'type': 'conditional_expression', 'children': ['169', '170', '175'], 'value': 'if'},{'id': '169', 'type': 'True', 'children': []},{'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': '=='},{'id': '171', 'type': 'binary_operator', 'children': ['172', '173'], 'value': '%'},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'y_num'},{'id': '173', 'type': 'integer', 'children': [], 'value': '2'},{'id': '174', 'type': 'integer', 'children': [], 'value': '0'},{'id': '175', 'type': 'False', 'children': []},{'id': '176', 'type': 'if_statement', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '178', 'type': 'block', 'children': ['179']},{'id': '179', 'type': 'break_statement', 'children': []},{'id': '180', 'type': 'if_statement', 'children': ['181', '183']},{'id': '181', 'type': 'not_operator', 'children': ['182']},{'id': '182', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '183', 'type': 'block', 'children': ['184', '191', '199']},{'id': '184', 'type': 'expression_statement', 'children': ['185']},{'id': '185', 'type': 'call', 'children': ['186', '189']},{'id': '186', 'type': 'attribute', 'children': ['187', '188']},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'logical_disks_shared'},{'id': '188', 'type': 'identifier', 'children': [], 'value': 'remove'},{'id': '189', 'type': 'argument_list', 'children': ['190']},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'x'},{'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': 'logical_disks_shared'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'insert'},{'id': '196', 'type': 'argument_list', 'children': ['197', '198']},{'id': '197', 'type': 'integer', 'children': [], 'value': '0'},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '199', 'type': 'expression_statement', 'children': ['200']},{'id': '200', 'type': 'assignment', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'check'},{'id': '202', 'type': 'True', 'children': []},{'id': '203', 'type': 'expression_statement', 'children': ['204']},{'id': '204', 'type': 'assignment', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'logical_disks_sorted'},{'id': '206', 'type': '()', 'children': ['207']},{'id': '207', 'type': 'binary_operator', 'children': ['208', '211'], 'value': '+'},{'id': '208', 'type': 'binary_operator', 'children': ['209', '210'], 'value': '+'},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'logical_disks_nonshared'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'logical_disks_shared_raid1'},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'logical_disks_shared'},{'id': '212', 'type': 'return_statement', 'children': ['213']},{'id': '213', 'type': 'identifier', 'children': [], 'value': 'logical_disks_sorted'}
def _sort_shared_logical_disks(logical_disks): is_shared = (lambda x: True if ('share_physical_disks' in x and x['share_physical_disks']) else False) num_of_disks = (lambda x: x['number_of_physical_disks'] if 'number_of_physical_disks' in x else constants.RAID_LEVEL_MIN_DISKS[x['raid_level']]) logical_disks_shared = [] logical_disks_nonshared = [] for x in logical_disks: target = (logical_disks_shared if is_shared(x) else logical_disks_nonshared) target.append(x) logical_disks_shared_raid1 = [] logical_disks_shared_excl_raid1 = [] for x in logical_disks_shared: target = (logical_disks_shared_raid1 if x['raid_level'] == '1' else logical_disks_shared_excl_raid1) target.append(x) logical_disks_shared = sorted(logical_disks_shared_excl_raid1, reverse=True, key=num_of_disks) check = True for x in logical_disks_shared: if x['raid_level'] == "1+0": x_num = num_of_disks(x) for y in logical_disks_shared: if y['raid_level'] != "1+0": y_num = num_of_disks(y) if x_num < y_num: check = (True if y_num % 2 == 0 else False) if check: break if not check: logical_disks_shared.remove(x) logical_disks_shared.insert(0, x) check = True logical_disks_sorted = (logical_disks_nonshared + logical_disks_shared_raid1 + logical_disks_shared) return logical_disks_sorted
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_versions'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '28', '47']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '14', 'type': 'list', 'children': ['15', '23'], 'value': '[\n cls.bucket_id == as_bucket_id(bucket),\n cls.key == key,\n ]'},{'id': '15', 'type': 'comparison_operator', 'children': ['16', '19'], 'value': '=='},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'bucket_id'},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'as_bucket_id'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '23', 'type': 'comparison_operator', 'children': ['24', '27'], 'value': '=='},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'id': '29', 'type': 'assignment', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'order'},{'id': '31', 'type': 'conditional_expression', 'children': ['32', '39', '40'], 'value': 'if'},{'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': 'cls'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'created'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '38', 'type': 'argument_list', 'children': []},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'desc'},{'id': '40', 'type': 'call', 'children': ['41', '46']},{'id': '41', 'type': 'attribute', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'created'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'asc'},{'id': '46', 'type': 'argument_list', 'children': []},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '60']},{'id': '49', 'type': 'attribute', 'children': ['50', '59']},{'id': '50', 'type': 'call', 'children': ['51', '56']},{'id': '51', 'type': 'attribute', 'children': ['52', '55']},{'id': '52', 'type': 'attribute', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'query'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'filter'},{'id': '56', 'type': 'argument_list', 'children': ['57']},{'id': '57', 'type': 'list_splat', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'filters'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'order_by'},{'id': '60', 'type': 'argument_list', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'cls'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'order'}
def get_versions(cls, bucket, key, desc=True): filters = [ cls.bucket_id == as_bucket_id(bucket), cls.key == key, ] order = cls.created.desc() if desc else cls.created.asc() return cls.query.filter(*filters).order_by(cls.key, order)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'ids'},{'id': '7', 'type': 'block', 'children': ['8', '25', '58']},{'id': '8', 'type': 'expression_statement', 'children': ['9']},{'id': '9', 'type': 'assignment', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '11', 'type': 'dictionary_comprehension', 'children': ['12', '22']},{'id': '12', 'type': 'pair', 'children': ['13', '19']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '15', 'type': 'argument_list', 'children': ['16']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'f_'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'file_id'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'f_'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'f_'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'},{'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': 'filesmap'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'list_comprehension', 'children': ['34', '55']},{'id': '34', 'type': 'tuple', 'children': ['35', '42']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '39', 'type': 'argument_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '42', 'type': 'call', 'children': ['43', '54']},{'id': '43', 'type': 'attribute', 'children': ['44', '53']},{'id': '44', 'type': 'subscript', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'call', 'children': ['47', '50']},{'id': '47', 'type': 'attribute', 'children': ['48', '49']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'dumps'},{'id': '54', 'type': 'argument_list', 'children': []},{'id': '55', 'type': 'for_in_clause', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'id_'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'ids'},{'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': 'self'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'flush'},{'id': '63', 'type': 'argument_list', 'children': []}
def sort_by(self, *ids): files = {str(f_.file_id): f_.key for f_ in self} self.filesmap = OrderedDict([ (files.get(id_, id_), self[files.get(id_, id_)].dumps()) for id_ in ids ]) self.flush()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_files_from_bucket'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '15', '22', '36', '49']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '12', 'type': 'boolean_operator', 'children': ['13', '14'], 'value': 'or'},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '14', 'type': 'list', 'children': [], 'value': '[]'},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'assignment', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '30', 'type': 'argument_list', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'total'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'assignment', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '39', 'type': 'call', 'children': ['40', '48']},{'id': '40', 'type': 'attribute', 'children': ['41', '47']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'ObjectVersion'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_by_bucket'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'bucket'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '48', 'type': 'argument_list', 'children': []},{'id': '49', 'type': 'return_statement', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '52', 'type': 'argument_list', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '54', 'type': 'keyword_argument', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '56', 'type': 'lambda', 'children': ['57', '59']},{'id': '57', 'type': 'lambda_parameters', 'children': ['58']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '59', 'type': 'call', 'children': ['60', '63']},{'id': '60', 'type': 'attribute', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sortby'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '63', 'type': 'argument_list', 'children': ['64', '67']},{'id': '64', 'type': 'attribute', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'total'}
def sorted_files_from_bucket(bucket, keys=None): keys = keys or [] total = len(keys) sortby = dict(zip(keys, range(total))) values = ObjectVersion.get_by_bucket(bucket).all() return sorted(values, key=lambda x: sortby.get(x.key, total))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_data'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '6', 'type': 'block', 'children': ['7', '18', '28']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'xy'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '15', 'type': 'argument_list', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '23']},{'id': '20', 'type': 'pattern_list', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'list_splat', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'xy'},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'expression_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'y'}
def sort_data(x, y): xy = sorted(zip(x, y)) x, y = zip(*xy) return x, y
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'unsort_vector'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'indices_of_increasing'},{'id': '6', 'type': 'block', 'children': ['7']},{'id': '7', 'type': 'return_statement', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'numpy'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '12', 'type': 'argument_list', 'children': ['13']},{'id': '13', 'type': 'list_comprehension', 'children': ['14', '22']},{'id': '14', 'type': 'subscript', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '16', 'type': 'call', 'children': ['17', '20']},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'indices_of_increasing'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'call', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '29', 'type': 'argument_list', 'children': ['30']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'data'}
def unsort_vector(data, indices_of_increasing): return numpy.array([data[indices_of_increasing.index(i)] for i in range(len(data))])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_compute_sorted_indices'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '55', '63']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sorted_indices'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'for_statement', 'children': ['11', '12', '20']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'to_sort'},{'id': '12', 'type': 'binary_operator', 'children': ['13', '17'], 'value': '+'},{'id': '13', 'type': 'list', 'children': ['14'], 'value': '[self.y]'},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '17', 'type': 'attribute', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '20', 'type': 'block', 'children': ['21', '36', '42']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'data_w_indices'},{'id': '24', 'type': 'list_comprehension', 'children': ['25', '28']},{'id': '25', 'type': 'tuple', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '28', 'type': 'for_in_clause', 'children': ['29', '32']},{'id': '29', 'type': 'tuple_pattern', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'to_sort'},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'data_w_indices'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'call', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'sorted_indices'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'list_comprehension', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '50', 'type': 'for_in_clause', 'children': ['51', '54']},{'id': '51', 'type': 'pattern_list', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'data_w_indices'},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '59', 'type': 'identifier', 'children': [], 'value': '_yi_sorted'},{'id': '60', 'type': 'subscript', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'sorted_indices'},{'id': '62', 'type': 'integer', 'children': [], 'value': '0'},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': '_xi_sorted'},{'id': '68', 'type': 'subscript', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'sorted_indices'},{'id': '70', 'type': 'slice', 'children': ['71', '72']},{'id': '71', 'type': 'integer', 'children': [], 'value': '1'},{'id': '72', 'type': 'colon', 'children': []}
def _compute_sorted_indices(self): sorted_indices = [] for to_sort in [self.y] + self.x: data_w_indices = [(val, i) for (i, val) in enumerate(to_sort)] data_w_indices.sort() sorted_indices.append([i for val, i in data_w_indices]) self._yi_sorted = sorted_indices[0] self._xi_sorted = sorted_indices[1:]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'specify_data_set'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'x_input'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'y_input'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort_data'},{'id': '9', 'type': 'False', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '88', '94']},{'id': '11', 'type': 'if_statement', 'children': ['12', '13', '78']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sort_data'},{'id': '13', 'type': 'block', 'children': ['14', '25', '35', '42', '57']},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'xy'},{'id': '17', 'type': 'call', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'x_input'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'y_input'},{'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': 'x'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'list_splat', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'xy'},{'id': '35', 'type': 'expression_statement', 'children': ['36']},{'id': '36', 'type': 'assignment', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'x_input_list'},{'id': '38', 'type': 'call', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'x_input'},{'id': '42', 'type': 'expression_statement', 'children': ['43']},{'id': '43', 'type': 'assignment', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '_original_index_of_xvalue'},{'id': '47', 'type': 'list_comprehension', 'children': ['48', '54']},{'id': '48', 'type': 'call', 'children': ['49', '52']},{'id': '49', 'type': 'attribute', 'children': ['50', '51']},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'x_input_list'},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '54', 'type': 'for_in_clause', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'xi'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '57', 'type': 'if_statement', 'children': ['58', '72']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '68'], 'value': '!='},{'id': '59', 'type': 'call', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '64', 'type': 'argument_list', 'children': ['65']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': '_original_index_of_xvalue'},{'id': '68', 'type': 'call', 'children': ['69', '70']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '72', 'type': 'block', 'children': ['73']},{'id': '73', 'type': 'raise_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'string', 'children': [], 'value': "'There are some non-unique x-values'"},{'id': '78', 'type': 'else_clause', 'children': ['79']},{'id': '79', 'type': 'block', 'children': ['80']},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '85']},{'id': '82', 'type': 'pattern_list', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '85', 'type': 'expression_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'x_input'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'y_input'},{'id': '88', 'type': 'expression_statement', 'children': ['89']},{'id': '89', 'type': 'assignment', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '99']},{'id': '96', 'type': 'attribute', 'children': ['97', '98']},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'y'}
def specify_data_set(self, x_input, y_input, sort_data=False): if sort_data: xy = sorted(zip(x_input, y_input)) x, y = zip(*xy) x_input_list = list(x_input) self._original_index_of_xvalue = [x_input_list.index(xi) for xi in x] if len(set(self._original_index_of_xvalue)) != len(x): raise RuntimeError('There are some non-unique x-values') else: x, y = x_input, y_input self.x = x self.y = y
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_aggregate'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'norm'},{'id': '7', 'type': 'True', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '10', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '17', '70', '86', '121', '131', '175']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'''\n Counts the number of occurances of each item in 'data'.\n Inputs\n data: a list of values.\n norm: normalize the resulting counts (as percent)\n sort_by: how to sort the retured data. Options are 'value' and 'count'.\n Output\n a non-redundant list of values (from 'data') and a list of counts.\n '''"},{'id': '17', 'type': 'if_statement', 'children': ['18', '19', '45']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '19', 'type': 'block', 'children': ['20', '30']},{'id': '20', 'type': 'expression_statement', 'children': ['21']},{'id': '21', 'type': 'assignment', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'vdict'},{'id': '23', 'type': 'dictionary_comprehension', 'children': ['24', '27']},{'id': '24', 'type': 'pair', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '26', 'type': 'integer', 'children': [], 'value': '0'},{'id': '27', 'type': 'for_in_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '30', 'type': 'for_statement', 'children': ['31', '32', '33']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'if_statement', 'children': ['35', '38']},{'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'in'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'augmented_assignment', 'children': ['41', '44'], 'value': '+='},{'id': '41', 'type': 'subscript', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'vdict'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '44', 'type': 'integer', 'children': [], 'value': '1'},{'id': '45', 'type': 'else_clause', 'children': ['46']},{'id': '46', 'type': 'block', 'children': ['47', '51']},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'assignment', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'vdict'},{'id': '50', 'type': 'dictionary', 'children': []},{'id': '51', 'type': 'for_statement', 'children': ['52', '53', '54']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '60']},{'id': '57', 'type': 'subscript', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'vdict'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '60', 'type': 'conditional_expression', 'children': ['61', '66', '69'], 'value': 'if'},{'id': '61', 'type': 'binary_operator', 'children': ['62', '65'], 'value': '+'},{'id': '62', 'type': 'subscript', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'vdict'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '65', 'type': 'integer', 'children': [], 'value': '1'},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'in'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'vdict'},{'id': '69', 'type': 'integer', 'children': [], 'value': '1'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '73', 'type': 'list_comprehension', 'children': ['74', '77']},{'id': '74', 'type': 'tuple', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '77', 'type': 'for_in_clause', 'children': ['78', '81']},{'id': '78', 'type': 'pattern_list', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'vdict'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'if_statement', 'children': ['87', '90', '105']},{'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '=='},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'sort_by'},{'id': '89', 'type': 'string', 'children': [], 'value': "'value'"},{'id': '90', 'type': 'block', 'children': ['91']},{'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': 'vals'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '96', 'type': 'argument_list', 'children': ['97']},{'id': '97', 'type': 'keyword_argument', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '99', 'type': 'lambda', 'children': ['100', '102']},{'id': '100', 'type': 'lambda_parameters', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '102', 'type': 'subscript', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '104', 'type': 'integer', 'children': [], 'value': '0'},{'id': '105', 'type': 'else_clause', 'children': ['106']},{'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': 'vals'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'keyword_argument', 'children': ['114', '115']},{'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '115', 'type': 'lambda', 'children': ['116', '118']},{'id': '116', 'type': 'lambda_parameters', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '118', 'type': 'subscript', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '120', 'type': 'integer', 'children': [], 'value': '1'},{'id': '121', 'type': 'expression_statement', 'children': ['122']},{'id': '122', 'type': 'assignment', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '124', 'type': 'list_comprehension', 'children': ['125', '128']},{'id': '125', 'type': 'subscript', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '127', 'type': 'integer', 'children': [], 'value': '0'},{'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']},{'id': '129', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '131', 'type': 'if_statement', 'children': ['132', '133', '163']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'norm'},{'id': '133', 'type': 'block', 'children': ['134', '144', '151']},{'id': '134', 'type': 'expression_statement', 'children': ['135']},{'id': '135', 'type': 'assignment', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'raw_y'},{'id': '137', 'type': 'list_comprehension', 'children': ['138', '141']},{'id': '138', 'type': 'subscript', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '140', 'type': 'integer', 'children': [], 'value': '1'},{'id': '141', 'type': 'for_in_clause', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '144', 'type': 'expression_statement', 'children': ['145']},{'id': '145', 'type': 'assignment', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'total_y'},{'id': '147', 'type': 'call', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'sum'},{'id': '149', 'type': 'argument_list', 'children': ['150']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'raw_y'},{'id': '151', 'type': 'expression_statement', 'children': ['152']},{'id': '152', 'type': 'assignment', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'ys'},{'id': '154', 'type': 'list_comprehension', 'children': ['155', '160']},{'id': '155', 'type': 'binary_operator', 'children': ['156', '159'], 'value': '/'},{'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '*'},{'id': '157', 'type': 'float', 'children': [], 'value': '100.'},{'id': '158', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'total_y'},{'id': '160', 'type': 'for_in_clause', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'y'},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'raw_y'},{'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', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'ys'},{'id': '168', 'type': 'list_comprehension', 'children': ['169', '172']},{'id': '169', 'type': 'subscript', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '171', 'type': 'integer', 'children': [], 'value': '1'},{'id': '172', 'type': 'for_in_clause', 'children': ['173', '174']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'vals'},{'id': '175', 'type': 'return_statement', 'children': ['176']},{'id': '176', 'type': 'expression_list', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'xs'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'ys'}
def _aggregate(data, norm=True, sort_by='value', keys=None): ''' Counts the number of occurances of each item in 'data'. Inputs data: a list of values. norm: normalize the resulting counts (as percent) sort_by: how to sort the retured data. Options are 'value' and 'count'. Output a non-redundant list of values (from 'data') and a list of counts. ''' if keys: vdict = {k: 0 for k in keys} for d in data: if d in keys: vdict[d] += 1 else: vdict = {} for d in data: vdict[d] = vdict[d] + 1 if d in vdict else 1 vals = [(k, v) for k, v in vdict.items()] if sort_by == 'value': vals.sort(key=lambda x: x[0]) else: vals.sort(key=lambda x: x[1]) xs = [v[0] for v in vals] if norm: raw_y = [v[1] for v in vals] total_y = sum(raw_y) ys = [100. * y / total_y for y in raw_y] else: ys = [v[1] for v in vals] return xs, ys
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_files'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'block', 'children': ['9', '11', '53', '125']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'string', 'children': [], 'value': "'''\n Lists files in a given directory.\n Args:\n d (str): Path to a directory.\n extension (str): If supplied, only files that contain the\n specificied extension will be returned. Default is ``False``,\n which returns all files in ``d``.\n Returns:\n list: A sorted list of file paths.\n '''"},{'id': '11', 'type': 'if_statement', 'children': ['12', '20', '46']},{'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': 'os'},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'path'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'isdir'},{'id': '18', 'type': 'argument_list', 'children': ['19']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '20', 'type': 'block', 'children': ['21', '32']},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'expanded_dir'},{'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': 'expanduser'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'glob'},{'id': '42', 'type': 'argument_list', 'children': ['43']},{'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '+'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'expanded_dir'},{'id': '45', 'type': 'string', 'children': [], 'value': "'/*'"},{'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': 'files'},{'id': '51', 'type': 'list', 'children': ['52'], 'value': '[d, ]'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'd'},{'id': '53', 'type': 'if_statement', 'children': ['54', '57']},{'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '56', 'type': 'None', 'children': []},{'id': '57', 'type': 'block', 'children': ['58', '71']},{'id': '58', 'type': 'if_statement', 'children': ['59', '65']},{'id': '59', 'type': 'comparison_operator', 'children': ['60', '64'], 'value': 'in'},{'id': '60', 'type': 'call', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'STR_TYPES'},{'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': 'extension'},{'id': '69', 'type': 'list', 'children': ['70'], 'value': '[extension, ]'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '71', 'type': 'expression_statement', 'children': ['72']},{'id': '72', 'type': 'assignment', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '74', 'type': 'list_comprehension', 'children': ['75', '76', '79']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '76', 'type': 'for_in_clause', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '79', 'type': 'if_clause', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'list', 'children': ['84', '95', '110'], 'value': "[f.split('.')[-1] in extension,\n f.split('.')[-1].upper() in extension,\n f.split('.')[-1].lower() in extension]"},{'id': '84', 'type': 'comparison_operator', 'children': ['85', '94'], 'value': 'in'},{'id': '85', 'type': 'subscript', 'children': ['86', '92']},{'id': '86', 'type': 'call', 'children': ['87', '90']},{'id': '87', 'type': 'attribute', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '90', 'type': 'argument_list', 'children': ['91']},{'id': '91', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '92', 'type': 'unary_operator', 'children': ['93'], 'value': '-'},{'id': '93', 'type': 'integer', 'children': [], 'value': '1'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '95', 'type': 'comparison_operator', 'children': ['96', '109'], 'value': 'in'},{'id': '96', 'type': 'call', 'children': ['97', '108']},{'id': '97', 'type': 'attribute', 'children': ['98', '107']},{'id': '98', 'type': 'subscript', 'children': ['99', '105']},{'id': '99', 'type': 'call', 'children': ['100', '103']},{'id': '100', 'type': 'attribute', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '105', 'type': 'unary_operator', 'children': ['106'], 'value': '-'},{'id': '106', 'type': 'integer', 'children': [], 'value': '1'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'upper'},{'id': '108', 'type': 'argument_list', 'children': []},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '110', 'type': 'comparison_operator', 'children': ['111', '124'], 'value': 'in'},{'id': '111', 'type': 'call', 'children': ['112', '123']},{'id': '112', 'type': 'attribute', 'children': ['113', '122']},{'id': '113', 'type': 'subscript', 'children': ['114', '120']},{'id': '114', 'type': 'call', 'children': ['115', '118']},{'id': '115', 'type': 'attribute', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '118', 'type': 'argument_list', 'children': ['119']},{'id': '119', 'type': 'string', 'children': [], 'value': "'.'"},{'id': '120', 'type': 'unary_operator', 'children': ['121'], 'value': '-'},{'id': '121', 'type': 'integer', 'children': [], 'value': '1'},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '123', 'type': 'argument_list', 'children': []},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'extension'},{'id': '125', 'type': 'return_statement', 'children': ['126']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'files'}
def list_files(d, extension=None): ''' Lists files in a given directory. Args: d (str): Path to a directory. extension (str): If supplied, only files that contain the specificied extension will be returned. Default is ``False``, which returns all files in ``d``. Returns: list: A sorted list of file paths. ''' if os.path.isdir(d): expanded_dir = os.path.expanduser(d) files = sorted(glob.glob(expanded_dir + '/*')) else: files = [d, ] if extension is not None: if type(extension) in STR_TYPES: extension = [extension, ] files = [f for f in files if any([f.split('.')[-1] in extension, f.split('.')[-1].upper() in extension, f.split('.')[-1].lower() in extension])] return files
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_collections'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '5', 'type': 'default_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'block', 'children': ['15', '17', '25', '36', '56', '76']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'string', 'children': [], 'value': "'''\n Returns a sorted list of collection names found in ``db``.\n Arguments:\n db (Database): A pymongo Database object. Can be obtained\n with ``get_db``.\n collection (str): Name of a collection. If the collection is\n present in the MongoDB database, a single-element list will\n be returned with the collecion name. If not, an empty list\n will be returned. This option is primarly included to allow\n for quick checking to see if a collection name is present.\n Default is None, which results in this option being ignored.\n prefix (str): If supplied, only collections that begin with\n ``prefix`` will be returned.\n suffix (str): If supplied, only collections that end with\n ``suffix`` will be returned.\n Returns:\n list: A sorted list of collection names.\n '''"},{'id': '17', 'type': 'if_statement', 'children': ['18', '21']},{'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '20', 'type': 'None', 'children': []},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'list', 'children': ['24'], 'value': '[collection, ]'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'collection'},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'db'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'collection_names'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'include_system_collections'},{'id': '35', 'type': 'False', 'children': []},{'id': '36', 'type': 'if_statement', 'children': ['37', '40']},{'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '39', 'type': 'None', 'children': []},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '44', 'type': 'list_comprehension', 'children': ['45', '46', '49']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '46', 'type': 'for_in_clause', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '49', 'type': 'if_clause', 'children': ['50']},{'id': '50', 'type': 'call', 'children': ['51', '54']},{'id': '51', 'type': 'attribute', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '54', 'type': 'argument_list', 'children': ['55']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '56', 'type': 'if_statement', 'children': ['57', '60']},{'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'is'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '59', 'type': 'None', 'children': []},{'id': '60', 'type': 'block', 'children': ['61']},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'assignment', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '64', 'type': 'list_comprehension', 'children': ['65', '66', '69']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'collections'},{'id': '69', 'type': 'if_clause', 'children': ['70']},{'id': '70', 'type': 'call', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'c'},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'endswith'},{'id': '74', 'type': 'argument_list', 'children': ['75']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'suffix'},{'id': '76', 'type': 'return_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'collections'}
def get_collections(db, collection=None, prefix=None, suffix=None): ''' Returns a sorted list of collection names found in ``db``. Arguments: db (Database): A pymongo Database object. Can be obtained with ``get_db``. collection (str): Name of a collection. If the collection is present in the MongoDB database, a single-element list will be returned with the collecion name. If not, an empty list will be returned. This option is primarly included to allow for quick checking to see if a collection name is present. Default is None, which results in this option being ignored. prefix (str): If supplied, only collections that begin with ``prefix`` will be returned. suffix (str): If supplied, only collections that end with ``suffix`` will be returned. Returns: list: A sorted list of collection names. ''' if collection is not None: return [collection, ] collections = db.collection_names(include_system_collections=False) if prefix is not None: collections = [c for c in collections if c.startswith(prefix)] if suffix is not None: collections = [c for c in collections if c.endswith(suffix)] return sorted(collections)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'leaf_nodes'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '23']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'deps'},{'id': '9', 'type': 'set_comprehension', 'children': ['10', '11', '20']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '11', 'type': 'for_in_clause', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'sublist'},{'id': '13', 'type': 'call', 'children': ['14', '19']},{'id': '14', 'type': 'attribute', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '19', 'type': 'argument_list', 'children': []},{'id': '20', 'type': 'for_in_clause', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'item'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sublist'},{'id': '23', 'type': 'return_statement', 'children': ['24']},{'id': '24', 'type': 'binary_operator', 'children': ['25', '28'], 'value': '-'},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'deps'}
def leaf_nodes(self): deps = {item for sublist in self.edges.values() for item in sublist} return self.nodes - deps
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'while_statement', 'children': ['7', '10']},{'id': '7', 'type': 'attribute', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '10', 'type': 'block', 'children': ['11', '15', '37']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'assignment', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'iterated'},{'id': '14', 'type': 'False', 'children': []},{'id': '15', 'type': 'for_statement', 'children': ['16', '17', '22']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '17', 'type': 'call', 'children': ['18', '21']},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'leaf_nodes'},{'id': '21', 'type': 'argument_list', 'children': []},{'id': '22', 'type': 'block', 'children': ['23', '27', '34']},{'id': '23', 'type': 'expression_statement', 'children': ['24']},{'id': '24', 'type': 'assignment', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'iterated'},{'id': '26', 'type': 'True', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'call', 'children': ['29', '32']},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'prune_node'},{'id': '32', 'type': 'argument_list', 'children': ['33']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'yield', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '37', 'type': 'if_statement', 'children': ['38', '40']},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'iterated'},{'id': '40', 'type': 'block', 'children': ['41']},{'id': '41', 'type': 'raise_statement', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'CyclicGraphError'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'string', 'children': [], 'value': '"Sorting has found a cyclic graph."'}
def sort(self): while self.nodes: iterated = False for node in self.leaf_nodes(): iterated = True self.prune_node(node) yield node if not iterated: raise CyclicGraphError("Sorting has found a cyclic graph.")
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'cycles'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '54', '75', '81', '119']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '11']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'walk_node'},{'id': '8', 'type': 'parameters', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '11', 'type': 'block', 'children': ['12', '22', '29']},{'id': '12', 'type': 'if_statement', 'children': ['13', '16']},{'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'in'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '16', 'type': 'block', 'children': ['17', '21']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'yield', 'children': ['19']},{'id': '19', 'type': 'tuple', 'children': ['20']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '21', 'type': 'return_statement', 'children': []},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '27', 'type': 'argument_list', 'children': ['28']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '29', 'type': 'for_statement', 'children': ['30', '31', '36']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '31', 'type': 'subscript', 'children': ['32', '35']},{'id': '32', 'type': 'attribute', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'edges'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '36', 'type': 'block', 'children': ['37']},{'id': '37', 'type': 'for_statement', 'children': ['38', '39', '47']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'walk_node'},{'id': '41', 'type': 'argument_list', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'edge'},{'id': '43', 'type': 'call', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '47', 'type': 'block', 'children': ['48']},{'id': '48', 'type': 'expression_statement', 'children': ['49']},{'id': '49', 'type': 'yield', 'children': ['50']},{'id': '50', 'type': 'binary_operator', 'children': ['51', '53'], 'value': '+'},{'id': '51', 'type': 'tuple', 'children': ['52']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'cycles'},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'from_iterable'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': 'generator_expression', 'children': ['63', '70']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'walk_node'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '67', 'type': 'call', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '69', 'type': 'argument_list', 'children': []},{'id': '70', 'type': 'for_in_clause', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'node'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '75', 'type': 'expression_statement', 'children': ['76']},{'id': '76', 'type': 'assignment', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'shortest'},{'id': '78', 'type': 'call', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '80', 'type': 'argument_list', 'children': []},{'id': '81', 'type': 'for_statement', 'children': ['82', '83', '90']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '85', 'type': 'argument_list', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'cycles'},{'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'for_statement', 'children': ['92', '93', '94', '110']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'shortest'},{'id': '94', 'type': 'block', 'children': ['95']},{'id': '95', 'type': 'if_statement', 'children': ['96', '108']},{'id': '96', 'type': 'call', 'children': ['97', '103']},{'id': '97', 'type': 'attribute', 'children': ['98', '102']},{'id': '98', 'type': 'call', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '100', 'type': 'argument_list', 'children': ['101']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'el'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'issubset'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'id': '104', 'type': 'call', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '106', 'type': 'argument_list', 'children': ['107']},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '108', 'type': 'block', 'children': ['109']},{'id': '109', 'type': 'break_statement', 'children': []},{'id': '110', 'type': 'else_clause', 'children': ['111']},{'id': '111', 'type': 'block', 'children': ['112']},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'shortest'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '117', 'type': 'argument_list', 'children': ['118']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'cycle'},{'id': '119', 'type': 'return_statement', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'shortest'}
def cycles(self): def walk_node(node, seen): if node in seen: yield (node,) return seen.add(node) for edge in self.edges[node]: for cycle in walk_node(edge, set(seen)): yield (node,) + cycle cycles = chain.from_iterable( (walk_node(node, set()) for node in self.nodes)) shortest = set() for cycle in sorted(cycles, key=len): for el in shortest: if set(el).issubset(set(cycle)): break else: shortest.add(cycle) return shortest
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_prepare_imports'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'dicts'},{'id': '6', 'type': 'block', 'children': ['7', '13', '17', '33', '70', '83', '146', '152', '158', '162', '211', '237', '254']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'pseudo_ids'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'set'},{'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': 'pseudo_matches'},{'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': 'prepared'},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '31']},{'id': '24', 'type': 'attribute', 'children': ['25', '30']},{'id': '25', 'type': 'call', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '27', 'type': 'argument_list', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'OrganizationImporter'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '30', 'type': 'identifier', 'children': [], 'value': '_prepare_imports'},{'id': '31', 'type': 'argument_list', 'children': ['32']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'dicts'},{'id': '33', 'type': 'for_statement', 'children': ['34', '37', '42']},{'id': '34', 'type': 'pattern_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '37', 'type': 'call', 'children': ['38', '41']},{'id': '38', 'type': 'attribute', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'prepared'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '41', 'type': 'argument_list', 'children': []},{'id': '42', 'type': 'block', 'children': ['43', '55']},{'id': '43', 'type': 'expression_statement', 'children': ['44']},{'id': '44', 'type': 'assignment', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '46', 'type': 'boolean_operator', 'children': ['47', '54'], 'value': 'or'},{'id': '47', 'type': 'call', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '51', 'type': 'argument_list', 'children': ['52', '53']},{'id': '52', 'type': 'string', 'children': [], 'value': "'parent_id'"},{'id': '53', 'type': 'None', 'children': []},{'id': '54', 'type': 'string', 'children': [], 'value': "''"},{'id': '55', 'type': 'if_statement', 'children': ['56', '62']},{'id': '56', 'type': 'call', 'children': ['57', '60']},{'id': '57', 'type': 'attribute', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'startswith'},{'id': '60', 'type': 'argument_list', 'children': ['61']},{'id': '61', 'type': 'string', 'children': [], 'value': "'~'"},{'id': '62', 'type': 'block', 'children': ['63']},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'call', 'children': ['65', '68']},{'id': '65', 'type': 'attribute', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'pseudo_ids'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '70', 'type': 'expression_statement', 'children': ['71']},{'id': '71', 'type': 'assignment', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'pseudo_ids'},{'id': '73', 'type': 'list_comprehension', 'children': ['74', '80']},{'id': '74', 'type': 'tuple', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'ppid'},{'id': '76', 'type': 'call', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_pseudo_id'},{'id': '78', 'type': 'argument_list', 'children': ['79']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'ppid'},{'id': '80', 'type': 'for_in_clause', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ppid'},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'pseudo_ids'},{'id': '83', 'type': 'for_statement', 'children': ['84', '87', '92']},{'id': '84', 'type': 'pattern_list', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'json_id'},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '87', 'type': 'call', 'children': ['88', '91']},{'id': '88', 'type': 'attribute', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'prepared'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '91', 'type': 'argument_list', 'children': []},{'id': '92', 'type': 'block', 'children': ['93']},{'id': '93', 'type': 'for_statement', 'children': ['94', '97', '98']},{'id': '94', 'type': 'pattern_list', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'ppid'},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'pseudo_ids'},{'id': '98', 'type': 'block', 'children': ['99', '103', '125']},{'id': '99', 'type': 'expression_statement', 'children': ['100']},{'id': '100', 'type': 'assignment', 'children': ['101', '102']},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '102', 'type': 'True', 'children': []},{'id': '103', 'type': 'for_statement', 'children': ['104', '107', '112']},{'id': '104', 'type': 'pattern_list', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '107', 'type': 'call', 'children': ['108', '111']},{'id': '108', 'type': 'attribute', 'children': ['109', '110']},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'spec'},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '111', 'type': 'argument_list', 'children': []},{'id': '112', 'type': 'block', 'children': ['113']},{'id': '113', 'type': 'if_statement', 'children': ['114', '119']},{'id': '114', 'type': 'comparison_operator', 'children': ['115', '118'], 'value': '!='},{'id': '115', 'type': 'subscript', 'children': ['116', '117']},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '119', 'type': 'block', 'children': ['120', '124']},{'id': '120', 'type': 'expression_statement', 'children': ['121']},{'id': '121', 'type': 'assignment', 'children': ['122', '123']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '123', 'type': 'False', 'children': []},{'id': '124', 'type': 'break_statement', 'children': []},{'id': '125', 'type': 'if_statement', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '127', 'type': 'block', 'children': ['128', '140']},{'id': '128', 'type': 'if_statement', 'children': ['129', '132']},{'id': '129', 'type': 'comparison_operator', 'children': ['130', '131'], 'value': 'in'},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'ppid'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'pseudo_matches'},{'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': 'UnresolvedIdError'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '+'},{'id': '138', 'type': 'string', 'children': [], 'value': "'multiple matches for pseudo id: '"},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'ppid'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'assignment', 'children': ['142', '145']},{'id': '142', 'type': 'subscript', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'pseudo_matches'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'ppid'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'json_id'},{'id': '146', 'type': 'expression_statement', 'children': ['147']},{'id': '147', 'type': 'assignment', 'children': ['148', '149']},{'id': '148', 'type': 'identifier', 'children': [], 'value': 'network'},{'id': '149', 'type': 'call', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'Network'},{'id': '151', 'type': 'argument_list', 'children': []},{'id': '152', 'type': 'expression_statement', 'children': ['153']},{'id': '153', 'type': 'assignment', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'in_network'},{'id': '155', 'type': 'call', 'children': ['156', '157']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '157', 'type': 'argument_list', 'children': []},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'import_order'},{'id': '161', 'type': 'list', 'children': [], 'value': '[]'},{'id': '162', 'type': 'for_statement', 'children': ['163', '166', '171']},{'id': '163', 'type': 'pattern_list', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'json_id'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '166', 'type': 'call', 'children': ['167', '170']},{'id': '167', 'type': 'attribute', 'children': ['168', '169']},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'prepared'},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '170', 'type': 'argument_list', 'children': []},{'id': '171', 'type': 'block', 'children': ['172', '182', '193', '200']},{'id': '172', 'type': 'expression_statement', 'children': ['173']},{'id': '173', 'type': 'assignment', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '175', 'type': 'call', 'children': ['176', '179']},{'id': '176', 'type': 'attribute', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'data'},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '179', 'type': 'argument_list', 'children': ['180', '181']},{'id': '180', 'type': 'string', 'children': [], 'value': "'parent_id'"},{'id': '181', 'type': 'None', 'children': []},{'id': '182', 'type': 'if_statement', 'children': ['183', '186']},{'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': 'in'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'pseudo_matches'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'assignment', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '190', 'type': 'subscript', 'children': ['191', '192']},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'pseudo_matches'},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'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': 'network'},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'add_node'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'json_id'},{'id': '200', 'type': 'if_statement', 'children': ['201', '202']},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'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': 'network'},{'id': '207', 'type': 'identifier', 'children': [], 'value': 'add_edge'},{'id': '208', 'type': 'argument_list', 'children': ['209', '210']},{'id': '209', 'type': 'identifier', 'children': [], 'value': 'parent_id'},{'id': '210', 'type': 'identifier', 'children': [], 'value': 'json_id'},{'id': '211', 'type': 'for_statement', 'children': ['212', '213', '218']},{'id': '212', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'network'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '217', 'type': 'argument_list', 'children': []},{'id': '218', 'type': 'block', 'children': ['219', '230']},{'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': 'import_order'},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '224', 'type': 'argument_list', 'children': ['225']},{'id': '225', 'type': 'tuple', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '227', 'type': 'subscript', 'children': ['228', '229']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'prepared'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'jid'},{'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': 'in_network'},{'id': '234', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '235', 'type': 'argument_list', 'children': ['236']},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'jid'},{'id': '237', 'type': 'if_statement', 'children': ['238', '248']},{'id': '238', 'type': 'comparison_operator', 'children': ['239', '240'], 'value': '!='},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'in_network'},{'id': '240', 'type': 'call', 'children': ['241', '242']},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'set'},{'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': 'prepared'},{'id': '246', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '247', 'type': 'argument_list', 'children': []},{'id': '248', 'type': 'block', 'children': ['249']},{'id': '249', 'type': 'raise_statement', 'children': ['250']},{'id': '250', 'type': 'call', 'children': ['251', '252']},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'PupaInternalError'},{'id': '252', 'type': 'argument_list', 'children': ['253']},{'id': '253', 'type': 'string', 'children': [], 'value': '"import is missing nodes in network set"'},{'id': '254', 'type': 'return_statement', 'children': ['255']},{'id': '255', 'type': 'identifier', 'children': [], 'value': 'import_order'}
def _prepare_imports(self, dicts): pseudo_ids = set() pseudo_matches = {} prepared = dict(super(OrganizationImporter, self)._prepare_imports(dicts)) for _, data in prepared.items(): parent_id = data.get('parent_id', None) or '' if parent_id.startswith('~'): pseudo_ids.add(parent_id) pseudo_ids = [(ppid, get_pseudo_id(ppid)) for ppid in pseudo_ids] for json_id, data in prepared.items(): for ppid, spec in pseudo_ids: match = True for k, v in spec.items(): if data[k] != v: match = False break if match: if ppid in pseudo_matches: raise UnresolvedIdError('multiple matches for pseudo id: ' + ppid) pseudo_matches[ppid] = json_id network = Network() in_network = set() import_order = [] for json_id, data in prepared.items(): parent_id = data.get('parent_id', None) if parent_id in pseudo_matches: parent_id = pseudo_matches[parent_id] network.add_node(json_id) if parent_id: network.add_edge(parent_id, json_id) for jid in network.sort(): import_order.append((jid, prepared[jid])) in_network.add(jid) if in_network != set(prepared.keys()): raise PupaInternalError("import is missing nodes in network set") return import_order
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'initial'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '8']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '6', 'type': 'list_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '10', 'type': 'block', 'children': ['11', '26', '47', '69']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '20']},{'id': '13', 'type': 'attribute', 'children': ['14', '19']},{'id': '14', 'type': 'call', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'super'},{'id': '16', 'type': 'argument_list', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'FlatMultipleModelMixin'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'initial'},{'id': '20', 'type': 'argument_list', 'children': ['21', '22', '24']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '22', 'type': 'list_splat', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '24', 'type': 'dictionary_splat', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '26', 'type': 'assert_statement', 'children': ['27', '36']},{'id': '27', 'type': 'not_operator', 'children': ['28']},{'id': '28', 'type': '()', 'children': ['29']},{'id': '29', 'type': 'boolean_operator', 'children': ['30', '33'], 'value': 'and'},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'sorting_field'},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sorting_fields'},{'id': '36', 'type': 'call', 'children': ['37', '41']},{'id': '37', 'type': 'attribute', 'children': ['38', '39', '40']},{'id': '38', 'type': 'string', 'children': [], 'value': "'{} should either define ``sorting_field`` or ``sorting_fields`` property, not both.'"},{'id': '39', 'type': 'line_continuation', 'children': [], 'value': '\\'},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'attribute', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '45', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '46', 'type': 'identifier', 'children': [], 'value': '__name__'},{'id': '47', 'type': 'if_statement', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'sorting_field'},{'id': '51', 'type': 'block', 'children': ['52', '60']},{'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': 'warnings'},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '57', 'type': 'argument_list', 'children': ['58', '59']},{'id': '58', 'type': 'string', 'children': [], 'value': "'``sorting_field`` property is pending its deprecation. Use ``sorting_fields`` instead.'"},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'DeprecationWarning'},{'id': '60', 'type': 'expression_statement', 'children': ['61']},{'id': '61', 'type': 'assignment', 'children': ['62', '65']},{'id': '62', 'type': 'attribute', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sorting_fields'},{'id': '65', 'type': 'list', 'children': ['66'], 'value': '[self.sorting_field]'},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'sorting_field'},{'id': '69', 'type': 'expression_statement', 'children': ['70']},{'id': '70', 'type': 'assignment', 'children': ['71', '74']},{'id': '71', 'type': 'attribute', 'children': ['72', '73']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '73', 'type': 'identifier', 'children': [], 'value': '_sorting_fields'},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'sorting_fields'}
def initial(self, request, *args, **kwargs): super(FlatMultipleModelMixin, self).initial(request, *args, **kwargs) assert not (self.sorting_field and self.sorting_fields), \ '{} should either define ``sorting_field`` or ``sorting_fields`` property, not both.' \ .format(self.__class__.__name__) if self.sorting_field: warnings.warn( '``sorting_field`` property is pending its deprecation. Use ``sorting_fields`` instead.', DeprecationWarning ) self.sorting_fields = [self.sorting_field] self._sorting_fields = self.sorting_fields
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'prepare_sorting_fields'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '47']},{'id': '6', 'type': 'if_statement', 'children': ['7', '16']},{'id': '7', 'type': 'comparison_operator', 'children': ['8', '11'], 'value': 'in'},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'sorting_parameter_name'},{'id': '11', 'type': 'attribute', 'children': ['12', '15']},{'id': '12', 'type': 'attribute', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'query_params'},{'id': '16', 'type': 'block', 'children': ['17']},{'id': '17', 'type': 'expression_statement', 'children': ['18']},{'id': '18', 'type': 'assignment', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_sorting_fields'},{'id': '22', 'type': 'list_comprehension', 'children': ['23', '28']},{'id': '23', 'type': 'call', 'children': ['24', '27']},{'id': '24', 'type': 'attribute', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '27', 'type': 'argument_list', 'children': []},{'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': '_'},{'id': '30', 'type': 'call', 'children': ['31', '45']},{'id': '31', 'type': 'attribute', 'children': ['32', '44']},{'id': '32', 'type': 'call', 'children': ['33', '40']},{'id': '33', 'type': 'attribute', 'children': ['34', '39']},{'id': '34', 'type': 'attribute', 'children': ['35', '38']},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'request'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'query_params'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '40', 'type': 'argument_list', 'children': ['41']},{'id': '41', 'type': 'attribute', 'children': ['42', '43']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'sorting_parameter_name'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'split'},{'id': '45', 'type': 'argument_list', 'children': ['46']},{'id': '46', 'type': 'string', 'children': [], 'value': "','"},{'id': '47', 'type': 'if_statement', 'children': ['48', '51']},{'id': '48', 'type': 'attribute', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '50', 'type': 'identifier', 'children': [], 'value': '_sorting_fields'},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '57']},{'id': '54', 'type': 'attribute', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '56', 'type': 'identifier', 'children': [], 'value': '_sorting_fields'},{'id': '57', 'type': 'list_comprehension', 'children': ['58', '83']},{'id': '58', 'type': 'tuple', 'children': ['59', '78']},{'id': '59', 'type': 'call', 'children': ['60', '65']},{'id': '60', 'type': 'attribute', 'children': ['61', '64']},{'id': '61', 'type': 'attribute', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'sorting_fields_map'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '65', 'type': 'argument_list', 'children': ['66', '72']},{'id': '66', 'type': 'call', 'children': ['67', '70']},{'id': '67', 'type': 'attribute', 'children': ['68', '69']},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '70', 'type': 'argument_list', 'children': ['71']},{'id': '71', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '72', 'type': 'call', 'children': ['73', '76']},{'id': '73', 'type': 'attribute', 'children': ['74', '75']},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'lstrip'},{'id': '76', 'type': 'argument_list', 'children': ['77']},{'id': '77', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '82'], 'value': '=='},{'id': '79', 'type': 'subscript', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '81', 'type': 'integer', 'children': [], 'value': '0'},{'id': '82', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '83', 'type': 'for_in_clause', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'field'},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': '_sorting_fields'}
def prepare_sorting_fields(self): if self.sorting_parameter_name in self.request.query_params: self._sorting_fields = [ _.strip() for _ in self.request.query_params.get(self.sorting_parameter_name).split(',') ] if self._sorting_fields: self._sorting_fields = [ (self.sorting_fields_map.get(field.lstrip('-'), field.lstrip('-')), field[0] == '-') for field in self._sorting_fields ]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'JSONList'},{'id': '3', 'type': 'parameters', 'children': ['4', '6']},{'id': '4', 'type': 'list_splat_pattern', 'children': ['5']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '8', 'type': 'block', 'children': ['9', '13', '31']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'JSON'},{'id': '13', 'type': 'try_statement', 'children': ['14', '27']},{'id': '14', 'type': 'block', 'children': ['15']},{'id': '15', 'type': 'if_statement', 'children': ['16', '22']},{'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': 'pop'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'string', 'children': [], 'value': '"unique_sorted"'},{'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': 'type_'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'JSONUniqueListType'},{'id': '27', 'type': 'except_clause', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'KeyError'},{'id': '29', 'type': 'block', 'children': ['30']},{'id': '30', 'type': 'pass_statement', 'children': []},{'id': '31', 'type': 'return_statement', 'children': ['32']},{'id': '32', 'type': 'call', 'children': ['33', '36']},{'id': '33', 'type': 'attribute', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'MutationList'},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'as_mutable'},{'id': '36', 'type': 'argument_list', 'children': ['37']},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'type_'},{'id': '39', 'type': 'argument_list', 'children': ['40', '42']},{'id': '40', 'type': 'list_splat', 'children': ['41']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'args'},{'id': '42', 'type': 'dictionary_splat', 'children': ['43']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def JSONList(*args, **kwargs): type_ = JSON try: if kwargs.pop("unique_sorted"): type_ = JSONUniqueListType except KeyError: pass return MutationList.as_mutable(type_(*args, **kwargs))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup_coords'},{'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']},{'id': '4', 'type': 'default_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'arr_names'},{'id': '6', 'type': 'None', 'children': []},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'default_parameter', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '12', 'type': 'dictionary', 'children': []},{'id': '13', 'type': 'dictionary_splat_pattern', 'children': ['14']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '15', 'type': 'block', 'children': ['16', '29', '54', '61', '80', '86', '172', '195']},{'id': '16', 'type': 'try_statement', 'children': ['17', '23']},{'id': '17', 'type': 'block', 'children': ['18']},{'id': '18', 'type': 'return_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '21', 'type': 'argument_list', 'children': ['22']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'arr_names'},{'id': '23', 'type': 'except_clause', 'children': ['24', '27']},{'id': '24', 'type': 'tuple', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'TypeError'},{'id': '27', 'type': 'block', 'children': ['28']},{'id': '28', 'type': 'pass_statement', 'children': []},{'id': '29', 'type': 'if_statement', 'children': ['30', '33', '41']},{'id': '30', 'type': 'comparison_operator', 'children': ['31', '32'], 'value': 'is'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'arr_names'},{'id': '32', 'type': 'None', 'children': []},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'assignment', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'arr_names'},{'id': '37', 'type': 'call', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '39', 'type': 'argument_list', 'children': ['40']},{'id': '40', 'type': 'string', 'children': [], 'value': "'arr{0}'"},{'id': '41', 'type': 'elif_clause', 'children': ['42', '46']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'isstring'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'arr_names'},{'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': 'arr_names'},{'id': '50', 'type': 'call', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'repeat'},{'id': '52', 'type': 'argument_list', 'children': ['53']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'arr_names'},{'id': '54', 'type': 'expression_statement', 'children': ['55']},{'id': '55', 'type': 'assignment', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '57', 'type': 'call', 'children': ['58', '59']},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '61', 'type': 'for_statement', 'children': ['62', '65', '71']},{'id': '62', 'type': 'pattern_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '65', 'type': 'call', 'children': ['66', '69']},{'id': '66', 'type': 'attribute', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '69', 'type': 'argument_list', 'children': ['70']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '71', 'type': 'block', 'children': ['72']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '77', 'type': 'argument_list', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'sorted_dims'},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '85', 'type': 'argument_list', 'children': []},{'id': '86', 'type': 'if_statement', 'children': ['87', '88', '121']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '88', 'type': 'block', 'children': ['89', '104']},{'id': '89', 'type': 'for_statement', 'children': ['90', '91', '92']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'sort'},{'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': 'sorted_dims'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '98', 'type': 'call', 'children': ['99', '102']},{'id': '99', 'type': 'attribute', 'children': ['100', '101']},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '104', 'type': 'for_statement', 'children': ['105', '108', '114']},{'id': '105', 'type': 'pattern_list', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '107', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '114', 'type': 'block', 'children': ['115']},{'id': '115', 'type': 'expression_statement', 'children': ['116']},{'id': '116', 'type': 'assignment', 'children': ['117', '120']},{'id': '117', 'type': 'subscript', 'children': ['118', '119']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'sorted_dims'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '121', 'type': 'else_clause', 'children': ['122']},{'id': '122', 'type': 'block', 'children': ['123', '134', '153']},{'id': '123', 'type': 'if_statement', 'children': ['124', '127']},{'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'in'},{'id': '125', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '127', 'type': 'block', 'children': ['128']},{'id': '128', 'type': 'expression_statement', 'children': ['129']},{'id': '129', 'type': 'assignment', 'children': ['130', '133']},{'id': '130', 'type': 'subscript', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'sorted_dims'},{'id': '132', 'type': 'string', 'children': [], 'value': "'name'"},{'id': '133', 'type': 'None', 'children': []},{'id': '134', 'type': 'for_statement', 'children': ['135', '138', '146']},{'id': '135', 'type': 'pattern_list', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '138', 'type': 'call', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '140', 'type': 'argument_list', 'children': ['141']},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'dims'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '145', 'type': 'argument_list', 'children': []},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '152']},{'id': '149', 'type': 'subscript', 'children': ['150', '151']},{'id': '150', 'type': 'identifier', 'children': [], 'value': 'sorted_dims'},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '152', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '153', 'type': 'for_statement', 'children': ['154', '157', '163']},{'id': '154', 'type': 'pattern_list', 'children': ['155', '156']},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '157', 'type': 'call', 'children': ['158', '161']},{'id': '158', 'type': 'attribute', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '161', 'type': 'argument_list', 'children': ['162']},{'id': '162', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '163', 'type': 'block', 'children': ['164']},{'id': '164', 'type': 'expression_statement', 'children': ['165']},{'id': '165', 'type': 'call', 'children': ['166', '169']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'sorted_dims'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '169', 'type': 'argument_list', 'children': ['170', '171']},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '172', 'type': 'for_statement', 'children': ['173', '176', '182']},{'id': '173', 'type': 'pattern_list', 'children': ['174', '175']},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '176', 'type': 'call', 'children': ['177', '180']},{'id': '177', 'type': 'attribute', 'children': ['178', '179']},{'id': '178', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '180', 'type': 'argument_list', 'children': ['181']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'sorted_dims'},{'id': '182', 'type': 'block', 'children': ['183']},{'id': '183', 'type': 'expression_statement', 'children': ['184']},{'id': '184', 'type': 'assignment', 'children': ['185', '188']},{'id': '185', 'type': 'subscript', 'children': ['186', '187']},{'id': '186', 'type': 'identifier', 'children': [], 'value': 'sorted_dims'},{'id': '187', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '188', 'type': 'call', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'iter'},{'id': '190', 'type': 'argument_list', 'children': ['191']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'safe_list'},{'id': '193', 'type': 'argument_list', 'children': ['194']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'val'},{'id': '195', 'type': 'return_statement', 'children': ['196']},{'id': '196', 'type': 'call', 'children': ['197', '198']},{'id': '197', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'},{'id': '198', 'type': 'argument_list', 'children': ['199']},{'id': '199', 'type': 'list_comprehension', 'children': ['200', '219']},{'id': '200', 'type': 'tuple', 'children': ['201', '207']},{'id': '201', 'type': 'call', 'children': ['202', '205']},{'id': '202', 'type': 'attribute', 'children': ['203', '204']},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'arr_name'},{'id': '204', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '205', 'type': 'argument_list', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '207', 'type': 'call', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'dict'},{'id': '209', 'type': 'argument_list', 'children': ['210']},{'id': '210', 'type': 'call', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '212', 'type': 'argument_list', 'children': ['213', '218']},{'id': '213', 'type': 'call', 'children': ['214', '217']},{'id': '214', 'type': 'attribute', 'children': ['215', '216']},{'id': '215', 'type': 'identifier', 'children': [], 'value': 'sorted_dims'},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '217', 'type': 'argument_list', 'children': []},{'id': '218', 'type': 'identifier', 'children': [], 'value': 'dim_tuple'},{'id': '219', 'type': 'for_in_clause', 'children': ['220', '225']},{'id': '220', 'type': 'pattern_list', 'children': ['221', '222']},{'id': '221', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '222', 'type': 'tuple_pattern', 'children': ['223', '224']},{'id': '223', 'type': 'identifier', 'children': [], 'value': 'arr_name'},{'id': '224', 'type': 'identifier', 'children': [], 'value': 'dim_tuple'},{'id': '225', 'type': 'call', 'children': ['226', '227']},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '227', 'type': 'argument_list', 'children': ['228']},{'id': '228', 'type': 'call', 'children': ['229', '230']},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'zip'},{'id': '230', 'type': 'argument_list', 'children': ['231', '232']},{'id': '231', 'type': 'identifier', 'children': [], 'value': 'arr_names'},{'id': '232', 'type': 'call', 'children': ['233', '234']},{'id': '233', 'type': 'identifier', 'children': [], 'value': 'product'},{'id': '234', 'type': 'argument_list', 'children': ['235']},{'id': '235', 'type': 'list_splat', 'children': ['236']},{'id': '236', 'type': 'call', 'children': ['237', '238']},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '238', 'type': 'argument_list', 'children': ['239', '240']},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '240', 'type': 'call', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'sorted_dims'},{'id': '243', 'type': 'identifier', 'children': [], 'value': 'values'},{'id': '244', 'type': 'argument_list', 'children': []}
def setup_coords(arr_names=None, sort=[], dims={}, **kwargs): try: return OrderedDict(arr_names) except (ValueError, TypeError): pass if arr_names is None: arr_names = repeat('arr{0}') elif isstring(arr_names): arr_names = repeat(arr_names) dims = OrderedDict(dims) for key, val in six.iteritems(kwargs): dims.setdefault(key, val) sorted_dims = OrderedDict() if sort: for key in sort: sorted_dims[key] = dims.pop(key) for key, val in six.iteritems(dims): sorted_dims[key] = val else: if 'name' in dims: sorted_dims['name'] = None for key, val in sorted(dims.items()): sorted_dims[key] = val for key, val in six.iteritems(kwargs): sorted_dims.setdefault(key, val) for key, val in six.iteritems(sorted_dims): sorted_dims[key] = iter(safe_list(val)) return OrderedDict([ (arr_name.format(i), dict(zip(sorted_dims.keys(), dim_tuple))) for i, (arr_name, dim_tuple) in enumerate(zip( arr_names, product( *map(list, sorted_dims.values()))))])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_tdata'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 't_format'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '6', 'type': 'block', 'children': ['7', '33', '36', '41', '45', '65', '74', '87', '138', '147', '158', '169']},{'id': '7', 'type': 'function_definition', 'children': ['8', '9', '11']},{'id': '8', 'type': 'function_name', 'children': [], 'value': 'median'},{'id': '9', 'type': 'parameters', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'binary_operator', 'children': ['14', '19'], 'value': '+'},{'id': '14', 'type': 'call', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '18', 'type': 'argument_list', 'children': []},{'id': '19', 'type': 'binary_operator', 'children': ['20', '32'], 'value': '/'},{'id': '20', 'type': '()', 'children': ['21']},{'id': '21', 'type': 'binary_operator', 'children': ['22', '27'], 'value': '-'},{'id': '22', 'type': 'call', 'children': ['23', '26']},{'id': '23', 'type': 'attribute', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'max'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'call', 'children': ['28', '31']},{'id': '28', 'type': 'attribute', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'arr'},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'min'},{'id': '31', 'type': 'argument_list', 'children': []},{'id': '32', 'type': 'integer', 'children': [], 'value': '2'},{'id': '33', 'type': 'import_statement', 'children': ['34']},{'id': '34', 'type': 'dotted_name', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '36', 'type': 'import_from_statement', 'children': ['37', '39']},{'id': '37', 'type': 'dotted_name', 'children': ['38']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'pandas'},{'id': '39', 'type': 'dotted_name', 'children': ['40']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 't_pattern'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 't_format'},{'id': '45', 'type': 'for_statement', 'children': ['46', '49', '54']},{'id': '46', 'type': 'pattern_list', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'patt'},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 't_patterns'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '53', 'type': 'argument_list', 'children': []},{'id': '54', 'type': 'block', 'children': ['55']},{'id': '55', 'type': 'expression_statement', 'children': ['56']},{'id': '56', 'type': 'assignment', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 't_pattern'},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 't_pattern'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '62', 'type': 'argument_list', 'children': ['63', '64']},{'id': '63', 'type': 'identifier', 'children': [], 'value': 'fmt'},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'patt'},{'id': '65', 'type': 'expression_statement', 'children': ['66']},{'id': '66', 'type': 'assignment', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 't_pattern'},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 're'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'compile'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 't_pattern'},{'id': '74', 'type': 'expression_statement', 'children': ['75']},{'id': '75', 'type': 'assignment', 'children': ['76', '77']},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '77', 'type': 'call', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '79', 'type': 'argument_list', 'children': ['80']},{'id': '80', 'type': 'call', 'children': ['81', '82']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'range'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'call', 'children': ['84', '85']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '87', 'type': 'for_statement', 'children': ['88', '91', '95']},{'id': '88', 'type': 'pattern_list', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '91', 'type': 'call', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'enumerate'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '95', 'type': 'block', 'children': ['96']},{'id': '96', 'type': 'expression_statement', 'children': ['97']},{'id': '97', 'type': 'assignment', 'children': ['98', '101']},{'id': '98', 'type': 'subscript', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'i'},{'id': '101', 'type': 'call', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'median'},{'id': '103', 'type': 'argument_list', 'children': ['104']},{'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': 'array'},{'id': '108', 'type': 'argument_list', 'children': ['109']},{'id': '109', 'type': 'call', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '111', 'type': 'argument_list', 'children': ['112']},{'id': '112', 'type': 'call', 'children': ['113', '114']},{'id': '113', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '114', 'type': 'argument_list', 'children': ['115', '132']},{'id': '115', 'type': 'lambda', 'children': ['116', '118']},{'id': '116', 'type': 'lambda_parameters', 'children': ['117']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '118', 'type': 'call', 'children': ['119', '122']},{'id': '119', 'type': 'attribute', 'children': ['120', '121']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '121', 'type': 'identifier', 'children': [], 'value': 'datetime64'},{'id': '122', 'type': 'argument_list', 'children': ['123']},{'id': '123', 'type': 'call', 'children': ['124', '129']},{'id': '124', 'type': 'attribute', 'children': ['125', '128']},{'id': '125', 'type': 'attribute', 'children': ['126', '127']},{'id': '126', 'type': 'identifier', 'children': [], 'value': 'dt'},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'datetime'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'strptime'},{'id': '129', 'type': 'argument_list', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 's'},{'id': '131', 'type': 'identifier', 'children': [], 'value': 't_format'},{'id': '132', 'type': 'call', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 't_pattern'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'findall'},{'id': '136', 'type': 'argument_list', 'children': ['137']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'f'},{'id': '138', 'type': 'expression_statement', 'children': ['139']},{'id': '139', 'type': 'assignment', 'children': ['140', '141']},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '141', 'type': 'call', 'children': ['142', '145']},{'id': '142', 'type': 'attribute', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '144', 'type': 'identifier', 'children': [], 'value': 'argsort'},{'id': '145', 'type': 'argument_list', 'children': ['146']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '147', 'type': 'expression_statement', 'children': ['148']},{'id': '148', 'type': 'assignment', 'children': ['149', '150']},{'id': '149', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '150', 'type': 'subscript', 'children': ['151', '157']},{'id': '151', 'type': 'call', 'children': ['152', '155']},{'id': '152', 'type': 'attribute', 'children': ['153', '154']},{'id': '153', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '158', 'type': 'expression_statement', 'children': ['159']},{'id': '159', 'type': 'assignment', 'children': ['160', '161']},{'id': '160', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '161', 'type': 'subscript', 'children': ['162', '168']},{'id': '162', 'type': 'call', 'children': ['163', '166']},{'id': '163', 'type': 'attribute', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'np'},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '166', 'type': 'argument_list', 'children': ['167']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'ind'},{'id': '169', 'type': 'return_statement', 'children': ['170']},{'id': '170', 'type': 'expression_list', 'children': ['171', '181']},{'id': '171', 'type': 'call', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'to_datetime'},{'id': '173', 'type': 'argument_list', 'children': ['174']},{'id': '174', 'type': 'call', 'children': ['175', '176']},{'id': '175', 'type': 'identifier', 'children': [], 'value': 'Index'},{'id': '176', 'type': 'argument_list', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'time'},{'id': '178', 'type': 'keyword_argument', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '180', 'type': 'string', 'children': [], 'value': "'time'"},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'files'}
def get_tdata(t_format, files): def median(arr): return arr.min() + (arr.max() - arr.min())/2 import re from pandas import Index t_pattern = t_format for fmt, patt in t_patterns.items(): t_pattern = t_pattern.replace(fmt, patt) t_pattern = re.compile(t_pattern) time = list(range(len(files))) for i, f in enumerate(files): time[i] = median(np.array(list(map( lambda s: np.datetime64(dt.datetime.strptime(s, t_format)), t_pattern.findall(f))))) ind = np.argsort(time) files = np.array(files)[ind] time = np.array(time)[ind] return to_datetime(Index(time, name='time')), files
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_set_and_filter'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '10', '16', '38', '217', '227', '239', '245', '253', '261']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'fmtos'},{'id': '9', 'type': 'list', 'children': [], 'value': '[]'},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '15', 'type': 'argument_list', 'children': []},{'id': '16', 'type': 'for_statement', 'children': ['17', '18', '21']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '20', 'type': 'identifier', 'children': [], 'value': '_force'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'expression_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '29']},{'id': '24', 'type': 'attribute', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '27', 'type': 'identifier', 'children': [], 'value': '_registered_updates'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'setdefault'},{'id': '29', 'type': 'argument_list', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '31', 'type': 'attribute', 'children': ['32', '37']},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '38', 'type': 'for_statement', 'children': ['39', '42', '76']},{'id': '39', 'type': 'pattern_list', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '44', 'type': 'argument_list', 'children': ['45', '53']},{'id': '45', 'type': 'call', 'children': ['46', '49']},{'id': '46', 'type': 'attribute', 'children': ['47', '48']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '49', 'type': 'argument_list', 'children': ['50']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '52', 'type': 'identifier', 'children': [], 'value': '_registered_updates'},{'id': '53', 'type': 'conditional_expression', 'children': ['54', '72', '75'], 'value': 'if'},{'id': '54', 'type': 'call', 'children': ['55', '58']},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'iteritems'},{'id': '58', 'type': 'argument_list', 'children': ['59']},{'id': '59', 'type': 'dictionary_comprehension', 'children': ['60', '69']},{'id': '60', 'type': 'pair', 'children': ['61', '62']},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '62', 'type': 'attribute', 'children': ['63', '68']},{'id': '63', 'type': 'call', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '65', 'type': 'argument_list', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'default'},{'id': '69', 'type': 'for_in_clause', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '72', 'type': 'attribute', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '74', 'type': 'identifier', 'children': [], 'value': '_todefault'},{'id': '75', 'type': 'tuple', 'children': []},{'id': '76', 'type': 'block', 'children': ['77', '83', '90', '98', '197', '207']},{'id': '77', 'type': 'if_statement', 'children': ['78', '81']},{'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'in'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '81', 'type': 'block', 'children': ['82']},{'id': '82', 'type': 'continue_statement', 'children': []},{'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': 'seen'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '90', 'type': 'expression_statement', 'children': ['91']},{'id': '91', 'type': 'assignment', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '93', 'type': 'call', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'getattr'},{'id': '95', 'type': 'argument_list', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '98', 'type': 'if_statement', 'children': ['99', '110', '145']},{'id': '99', 'type': 'boolean_operator', 'children': ['100', '105'], 'value': 'and'},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '102'], 'value': 'in'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '102', 'type': 'attribute', 'children': ['103', '104']},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '104', 'type': 'identifier', 'children': [], 'value': '_shared'},{'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'not'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': '_force'},{'id': '110', 'type': 'block', 'children': ['111', '141']},{'id': '111', 'type': 'if_statement', 'children': ['112', '122']},{'id': '112', 'type': 'not_operator', 'children': ['113']},{'id': '113', 'type': 'attribute', 'children': ['114', '121']},{'id': '114', 'type': 'attribute', 'children': ['115', '120']},{'id': '115', 'type': 'subscript', 'children': ['116', '119']},{'id': '116', 'type': 'attribute', 'children': ['117', '118']},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '118', 'type': 'identifier', 'children': [], 'value': '_shared'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'plotter'},{'id': '121', 'type': 'identifier', 'children': [], 'value': '_updating'},{'id': '122', 'type': 'block', 'children': ['123']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'call', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'warn'},{'id': '126', 'type': 'argument_list', 'children': ['127', '136']},{'id': '127', 'type': 'binary_operator', 'children': ['128', '132'], 'value': '%'},{'id': '128', 'type': '()', 'children': ['129']},{'id': '129', 'type': 'concatenated_string', 'children': ['130', '131']},{'id': '130', 'type': 'string', 'children': [], 'value': '"%s formatoption is shared with another plotter."'},{'id': '131', 'type': 'string', 'children': [], 'value': '" Use the unshare method to enable the updating"'},{'id': '132', 'type': '()', 'children': ['133']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '138', 'type': 'attribute', 'children': ['139', '140']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '140', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '141', 'type': 'expression_statement', 'children': ['142']},{'id': '142', 'type': 'assignment', 'children': ['143', '144']},{'id': '143', 'type': 'identifier', 'children': [], 'value': 'changed'},{'id': '144', 'type': 'False', 'children': []},{'id': '145', 'type': 'else_clause', 'children': ['146']},{'id': '146', 'type': 'block', 'children': ['147']},{'id': '147', 'type': 'try_statement', 'children': ['148', '169']},{'id': '148', 'type': 'block', 'children': ['149']},{'id': '149', 'type': 'expression_statement', 'children': ['150']},{'id': '150', 'type': 'assignment', 'children': ['151', '152']},{'id': '151', 'type': 'identifier', 'children': [], 'value': 'changed'},{'id': '152', 'type': 'call', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'check_and_set'},{'id': '156', 'type': 'argument_list', 'children': ['157', '158', '163']},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'value'},{'id': '158', 'type': 'keyword_argument', 'children': ['159', '160']},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'todefault'},{'id': '160', 'type': 'attribute', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '162', 'type': 'identifier', 'children': [], 'value': '_todefault'},{'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']},{'id': '164', 'type': 'identifier', 'children': [], 'value': 'validate'},{'id': '165', 'type': 'not_operator', 'children': ['166']},{'id': '166', 'type': 'attribute', 'children': ['167', '168']},{'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '168', 'type': 'identifier', 'children': [], 'value': 'no_validation'},{'id': '169', 'type': 'except_clause', 'children': ['170', '174']},{'id': '170', 'type': 'as_pattern', 'children': ['171', '172']},{'id': '171', 'type': 'identifier', 'children': [], 'value': 'Exception'},{'id': '172', 'type': 'as_pattern_target', 'children': ['173']},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '174', 'type': 'block', 'children': ['175', '185', '195']},{'id': '175', 'type': 'expression_statement', 'children': ['176']},{'id': '176', 'type': 'call', 'children': ['177', '182']},{'id': '177', 'type': 'attribute', 'children': ['178', '181']},{'id': '178', 'type': 'attribute', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '180', 'type': 'identifier', 'children': [], 'value': '_registered_updates'},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '182', 'type': 'argument_list', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '184', 'type': 'None', 'children': []},{'id': '185', 'type': 'expression_statement', 'children': ['186']},{'id': '186', 'type': 'call', 'children': ['187', '192']},{'id': '187', 'type': 'attribute', 'children': ['188', '191']},{'id': '188', 'type': 'attribute', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '190', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '191', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '192', 'type': 'argument_list', 'children': ['193', '194']},{'id': '193', 'type': 'string', 'children': [], 'value': "'Failed to set %s'"},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '195', 'type': 'raise_statement', 'children': ['196']},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'e'},{'id': '197', 'type': 'expression_statement', 'children': ['198']},{'id': '198', 'type': 'assignment', 'children': ['199', '200']},{'id': '199', 'type': 'identifier', 'children': [], 'value': 'changed'},{'id': '200', 'type': 'boolean_operator', 'children': ['201', '202'], 'value': 'or'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'changed'},{'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': 'in'},{'id': '203', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '206', 'type': 'identifier', 'children': [], 'value': '_force'},{'id': '207', 'type': 'if_statement', 'children': ['208', '209']},{'id': '208', 'type': 'identifier', 'children': [], 'value': 'changed'},{'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': 'fmtos'},{'id': '214', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '215', 'type': 'argument_list', 'children': ['216']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '217', 'type': 'expression_statement', 'children': ['218']},{'id': '218', 'type': 'assignment', 'children': ['219', '220']},{'id': '219', 'type': 'identifier', 'children': [], 'value': 'fmtos'},{'id': '220', 'type': 'call', 'children': ['221', '224']},{'id': '221', 'type': 'attribute', 'children': ['222', '223']},{'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '223', 'type': 'identifier', 'children': [], 'value': '_insert_additionals'},{'id': '224', 'type': 'argument_list', 'children': ['225', '226']},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'fmtos'},{'id': '226', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '227', 'type': 'for_statement', 'children': ['228', '229', '230']},{'id': '228', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '229', 'type': 'identifier', 'children': [], 'value': 'fmtos'},{'id': '230', 'type': 'block', 'children': ['231']},{'id': '231', 'type': 'expression_statement', 'children': ['232']},{'id': '232', 'type': 'call', 'children': ['233', '238']},{'id': '233', 'type': 'attribute', 'children': ['234', '237']},{'id': '234', 'type': 'attribute', 'children': ['235', '236']},{'id': '235', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '236', 'type': 'identifier', 'children': [], 'value': 'lock'},{'id': '237', 'type': 'identifier', 'children': [], 'value': 'acquire'},{'id': '238', 'type': 'argument_list', 'children': []},{'id': '239', 'type': 'expression_statement', 'children': ['240']},{'id': '240', 'type': 'assignment', 'children': ['241', '244']},{'id': '241', 'type': 'attribute', 'children': ['242', '243']},{'id': '242', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '243', 'type': 'identifier', 'children': [], 'value': '_todefault'},{'id': '244', 'type': 'False', 'children': []},{'id': '245', 'type': 'expression_statement', 'children': ['246']},{'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': 'self'},{'id': '250', 'type': 'identifier', 'children': [], 'value': '_registered_updates'},{'id': '251', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '252', 'type': 'argument_list', 'children': []},{'id': '253', 'type': 'expression_statement', 'children': ['254']},{'id': '254', 'type': 'call', 'children': ['255', '260']},{'id': '255', 'type': 'attribute', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '258', 'type': 'identifier', 'children': [], 'value': '_force'},{'id': '259', 'type': 'identifier', 'children': [], 'value': 'clear'},{'id': '260', 'type': 'argument_list', 'children': []},{'id': '261', 'type': 'return_statement', 'children': ['262']},{'id': '262', 'type': 'identifier', 'children': [], 'value': 'fmtos'}
def _set_and_filter(self): fmtos = [] seen = set() for key in self._force: self._registered_updates.setdefault(key, getattr(self, key).value) for key, value in chain( six.iteritems(self._registered_updates), six.iteritems( {key: getattr(self, key).default for key in self}) if self._todefault else ()): if key in seen: continue seen.add(key) fmto = getattr(self, key) if key in self._shared and key not in self._force: if not self._shared[key].plotter._updating: warn(("%s formatoption is shared with another plotter." " Use the unshare method to enable the updating") % ( fmto.key), logger=self.logger) changed = False else: try: changed = fmto.check_and_set( value, todefault=self._todefault, validate=not self.no_validation) except Exception as e: self._registered_updates.pop(key, None) self.logger.debug('Failed to set %s', key) raise e changed = changed or key in self._force if changed: fmtos.append(fmto) fmtos = self._insert_additionals(fmtos, seen) for fmto in fmtos: fmto.lock.acquire() self._todefault = False self._registered_updates.clear() self._force.clear() return fmtos
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_sorted_by_priority'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'fmtos'},{'id': '6', 'type': 'default_parameter', 'children': ['7', '8']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'changed'},{'id': '8', 'type': 'None', 'children': []},{'id': '9', 'type': 'block', 'children': ['10', '35', '112', '129', '139', '150', '160']},{'id': '10', 'type': 'function_definition', 'children': ['11', '12', '14']},{'id': '11', 'type': 'function_name', 'children': [], 'value': 'pop_fmto'},{'id': '12', 'type': 'parameters', 'children': ['13']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '14', 'type': 'block', 'children': ['15', '24', '28']},{'id': '15', 'type': 'expression_statement', 'children': ['16']},{'id': '16', 'type': 'assignment', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '18', 'type': 'call', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'fmtos_keys'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'index'},{'id': '22', 'type': 'argument_list', 'children': ['23']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '24', 'type': 'delete_statement', 'children': ['25']},{'id': '25', 'type': 'subscript', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'fmtos_keys'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '28', 'type': 'return_statement', 'children': ['29']},{'id': '29', 'type': 'call', 'children': ['30', '33']},{'id': '30', 'type': 'attribute', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'fmtos'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'idx'},{'id': '35', 'type': 'function_definition', 'children': ['36', '37', '40']},{'id': '36', 'type': 'function_name', 'children': [], 'value': 'get_children'},{'id': '37', 'type': 'parameters', 'children': ['38', '39']},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'parents_keys'},{'id': '40', 'type': 'block', 'children': ['41', '47']},{'id': '41', 'type': 'expression_statement', 'children': ['42']},{'id': '42', 'type': 'assignment', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'all_fmtos'},{'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '+'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'fmtos_keys'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'parents_keys'},{'id': '47', 'type': 'for_statement', 'children': ['48', '49', '56']},{'id': '48', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '49', 'type': 'binary_operator', 'children': ['50', '53'], 'value': '+'},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'children'},{'id': '53', 'type': 'attribute', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'dependencies'},{'id': '56', 'type': 'block', 'children': ['57', '63', '70', '86', '109']},{'id': '57', 'type': 'if_statement', 'children': ['58', '61']},{'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'not'},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'fmtos_keys'},{'id': '61', 'type': 'block', 'children': ['62']},{'id': '62', 'type': 'continue_statement', 'children': []},{'id': '63', 'type': 'expression_statement', 'children': ['64']},{'id': '64', 'type': 'assignment', 'children': ['65', '66']},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'child_fmto'},{'id': '66', 'type': 'call', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'pop_fmto'},{'id': '68', 'type': 'argument_list', 'children': ['69']},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '70', 'type': 'for_statement', 'children': ['71', '72', '82']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'childs_child'},{'id': '72', 'type': 'call', 'children': ['73', '74']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'get_children'},{'id': '74', 'type': 'argument_list', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'child_fmto'},{'id': '76', 'type': 'binary_operator', 'children': ['77', '78'], 'value': '+'},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'parents_keys'},{'id': '78', 'type': 'list', 'children': ['79'], 'value': '[child_fmto.key]'},{'id': '79', 'type': 'attribute', 'children': ['80', '81']},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'child_fmto'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '82', 'type': 'block', 'children': ['83']},{'id': '83', 'type': 'expression_statement', 'children': ['84']},{'id': '84', 'type': 'yield', 'children': ['85']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'childs_child'},{'id': '86', 'type': 'if_statement', 'children': ['87', '107']},{'id': '87', 'type': '()', 'children': ['88']},{'id': '88', 'type': 'boolean_operator', 'children': ['89', '100'], 'value': 'or'},{'id': '89', 'type': 'call', 'children': ['90', '91']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '91', 'type': 'generator_expression', 'children': ['92', '95']},{'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'in'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'all_fmtos'},{'id': '95', 'type': 'for_in_clause', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '97', 'type': 'attribute', 'children': ['98', '99']},{'id': '98', 'type': 'identifier', 'children': [], 'value': 'child_fmto'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '100', 'type': 'comparison_operator', 'children': ['101', '104'], 'value': 'in'},{'id': '101', 'type': 'attribute', 'children': ['102', '103']},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '103', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '104', 'type': 'attribute', 'children': ['105', '106']},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'child_fmto'},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '107', 'type': 'block', 'children': ['108']},{'id': '108', 'type': 'continue_statement', 'children': []},{'id': '109', 'type': 'expression_statement', 'children': ['110']},{'id': '110', 'type': 'yield', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'child_fmto'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'fmtos'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '117', 'type': 'argument_list', 'children': ['118', '126']},{'id': '118', 'type': 'keyword_argument', 'children': ['119', '120']},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '120', 'type': 'lambda', 'children': ['121', '123']},{'id': '121', 'type': 'lambda_parameters', 'children': ['122']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '123', 'type': 'attribute', 'children': ['124', '125']},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'priority'},{'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'reverse'},{'id': '128', 'type': 'True', 'children': []},{'id': '129', 'type': 'expression_statement', 'children': ['130']},{'id': '130', 'type': 'assignment', 'children': ['131', '132']},{'id': '131', 'type': 'identifier', 'children': [], 'value': 'fmtos_keys'},{'id': '132', 'type': 'list_comprehension', 'children': ['133', '136']},{'id': '133', 'type': 'attribute', 'children': ['134', '135']},{'id': '134', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '135', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '136', 'type': 'for_in_clause', 'children': ['137', '138']},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'fmtos'},{'id': '139', 'type': 'expression_statement', 'children': ['140']},{'id': '140', 'type': 'assignment', 'children': ['141', '144']},{'id': '141', 'type': 'attribute', 'children': ['142', '143']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '143', 'type': 'identifier', 'children': [], 'value': '_last_update'},{'id': '144', 'type': 'boolean_operator', 'children': ['145', '146'], 'value': 'or'},{'id': '145', 'type': 'identifier', 'children': [], 'value': 'changed'},{'id': '146', 'type': 'subscript', 'children': ['147', '148']},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'fmtos_keys'},{'id': '148', 'type': 'slice', 'children': ['149']},{'id': '149', 'type': 'colon', 'children': []},{'id': '150', 'type': 'expression_statement', 'children': ['151']},{'id': '151', 'type': 'call', 'children': ['152', '157']},{'id': '152', 'type': 'attribute', 'children': ['153', '156']},{'id': '153', 'type': 'attribute', 'children': ['154', '155']},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '155', 'type': 'identifier', 'children': [], 'value': 'logger'},{'id': '156', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '157', 'type': 'argument_list', 'children': ['158', '159']},{'id': '158', 'type': 'string', 'children': [], 'value': '"Update the formatoptions %s"'},{'id': '159', 'type': 'identifier', 'children': [], 'value': 'fmtos_keys'},{'id': '160', 'type': 'while_statement', 'children': ['161', '162']},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'fmtos'},{'id': '162', 'type': 'block', 'children': ['163', '167', '176', '190', '204']},{'id': '163', 'type': 'delete_statement', 'children': ['164']},{'id': '164', 'type': 'subscript', 'children': ['165', '166']},{'id': '165', 'type': 'identifier', 'children': [], 'value': 'fmtos_keys'},{'id': '166', 'type': 'integer', 'children': [], 'value': '0'},{'id': '167', 'type': 'expression_statement', 'children': ['168']},{'id': '168', 'type': 'assignment', 'children': ['169', '170']},{'id': '169', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '170', 'type': 'call', 'children': ['171', '174']},{'id': '171', 'type': 'attribute', 'children': ['172', '173']},{'id': '172', 'type': 'identifier', 'children': [], 'value': 'fmtos'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '174', 'type': 'argument_list', 'children': ['175']},{'id': '175', 'type': 'integer', 'children': [], 'value': '0'},{'id': '176', 'type': 'for_statement', 'children': ['177', '178', '186']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'child_fmto'},{'id': '178', 'type': 'call', 'children': ['179', '180']},{'id': '179', 'type': 'identifier', 'children': [], 'value': 'get_children'},{'id': '180', 'type': 'argument_list', 'children': ['181', '182']},{'id': '181', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '182', 'type': 'list', 'children': ['183'], 'value': '[fmto.key]'},{'id': '183', 'type': 'attribute', 'children': ['184', '185']},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '185', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '186', 'type': 'block', 'children': ['187']},{'id': '187', 'type': 'expression_statement', 'children': ['188']},{'id': '188', 'type': 'yield', 'children': ['189']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'child_fmto'},{'id': '190', 'type': 'if_statement', 'children': ['191', '202']},{'id': '191', 'type': 'call', 'children': ['192', '193']},{'id': '192', 'type': 'identifier', 'children': [], 'value': 'any'},{'id': '193', 'type': 'generator_expression', 'children': ['194', '197']},{'id': '194', 'type': 'comparison_operator', 'children': ['195', '196'], 'value': 'in'},{'id': '195', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '196', 'type': 'identifier', 'children': [], 'value': 'fmtos_keys'},{'id': '197', 'type': 'for_in_clause', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '199', 'type': 'attribute', 'children': ['200', '201']},{'id': '200', 'type': 'identifier', 'children': [], 'value': 'fmto'},{'id': '201', 'type': 'identifier', 'children': [], 'value': 'parents'},{'id': '202', 'type': 'block', 'children': ['203']},{'id': '203', 'type': 'continue_statement', 'children': []},{'id': '204', 'type': 'expression_statement', 'children': ['205']},{'id': '205', 'type': 'yield', 'children': ['206']},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'fmto'}
def _sorted_by_priority(self, fmtos, changed=None): def pop_fmto(key): idx = fmtos_keys.index(key) del fmtos_keys[idx] return fmtos.pop(idx) def get_children(fmto, parents_keys): all_fmtos = fmtos_keys + parents_keys for key in fmto.children + fmto.dependencies: if key not in fmtos_keys: continue child_fmto = pop_fmto(key) for childs_child in get_children( child_fmto, parents_keys + [child_fmto.key]): yield childs_child if (any(key in all_fmtos for key in child_fmto.parents) or fmto.key in child_fmto.parents): continue yield child_fmto fmtos.sort(key=lambda fmto: fmto.priority, reverse=True) fmtos_keys = [fmto.key for fmto in fmtos] self._last_update = changed or fmtos_keys[:] self.logger.debug("Update the formatoptions %s", fmtos_keys) while fmtos: del fmtos_keys[0] fmto = fmtos.pop(0) for child_fmto in get_children(fmto, [fmto.key]): yield child_fmto if any(key in fmtos_keys for key in fmto.parents): continue yield fmto
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_kwargs'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '5', 'type': 'list_splat_pattern', 'children': ['6']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'param_lists'},{'id': '7', 'type': 'block', 'children': ['8']},{'id': '8', 'type': 'return_statement', 'children': ['9']},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'chain'},{'id': '11', 'type': 'argument_list', 'children': ['12', '37']},{'id': '12', 'type': 'generator_expression', 'children': ['13', '30']},{'id': '13', 'type': 'dictionary_comprehension', 'children': ['14', '22']},{'id': '14', 'type': 'pair', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'key'},{'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': 'pop'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '22', 'type': 'for_in_clause', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '24', 'type': 'call', 'children': ['25', '28']},{'id': '25', 'type': 'attribute', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'intersection'},{'id': '28', 'type': 'argument_list', 'children': ['29']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'kwargs'},{'id': '30', 'type': 'for_in_clause', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '32', 'type': 'call', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '34', 'type': 'argument_list', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'param_lists'},{'id': '37', 'type': 'list', 'children': ['38'], 'value': '[kwargs]'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def sort_kwargs(kwargs, *param_lists): return chain( ({key: kwargs.pop(key) for key in params.intersection(kwargs)} for params in map(set, param_lists)), [kwargs])
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'iterkeys'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '12', '18', '24', '83']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'assignment', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'assignment', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '21', 'type': 'call', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'for_statement', 'children': ['25', '26', '34']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '26', 'type': 'call', 'children': ['27', '30']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'six'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'iterkeys'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'attribute', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'base'},{'id': '34', 'type': 'block', 'children': ['35']},{'id': '35', 'type': 'for_statement', 'children': ['36', '37', '38']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'patterns'},{'id': '38', 'type': 'block', 'children': ['39', '48']},{'id': '39', 'type': 'expression_statement', 'children': ['40']},{'id': '40', 'type': 'assignment', 'children': ['41', '42']},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '42', 'type': 'call', 'children': ['43', '46']},{'id': '43', 'type': 'attribute', 'children': ['44', '45']},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'pattern'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'match'},{'id': '46', 'type': 'argument_list', 'children': ['47']},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '48', 'type': 'if_statement', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '50', 'type': 'block', 'children': ['51', '67', '82']},{'id': '51', 'type': 'expression_statement', 'children': ['52']},{'id': '52', 'type': 'assignment', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '54', 'type': 'conditional_expression', 'children': ['55', '61', '62'], 'value': 'if'},{'id': '55', 'type': 'call', 'children': ['56', '59']},{'id': '56', 'type': 'attribute', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '58', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '59', 'type': 'argument_list', 'children': ['60']},{'id': '60', 'type': 'string', 'children': [], 'value': "'key'"},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'replace'},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'm'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'group'},{'id': '66', 'type': 'argument_list', 'children': []},{'id': '67', 'type': 'if_statement', 'children': ['68', '71']},{'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'not'},{'id': '69', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '71', 'type': 'block', 'children': ['72', '79']},{'id': '72', 'type': 'expression_statement', 'children': ['73']},{'id': '73', 'type': 'call', 'children': ['74', '77']},{'id': '74', 'type': 'attribute', 'children': ['75', '76']},{'id': '75', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '77', 'type': 'argument_list', 'children': ['78']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '79', 'type': 'expression_statement', 'children': ['80']},{'id': '80', 'type': 'yield', 'children': ['81']},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'ret'},{'id': '82', 'type': 'break_statement', 'children': []},{'id': '83', 'type': 'for_statement', 'children': ['84', '85', '91']},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '85', 'type': 'call', 'children': ['86', '89']},{'id': '86', 'type': 'attribute', 'children': ['87', '88']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'DictMethods'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'iterkeys'},{'id': '89', 'type': 'argument_list', 'children': ['90']},{'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '91', 'type': 'block', 'children': ['92']},{'id': '92', 'type': 'if_statement', 'children': ['93', '96']},{'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'not'},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'expression_statement', 'children': ['98']},{'id': '98', 'type': 'yield', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'}
def iterkeys(self): patterns = self.patterns replace = self.replace seen = set() for key in six.iterkeys(self.base): for pattern in patterns: m = pattern.match(key) if m: ret = m.group('key') if replace else m.group() if ret not in seen: seen.add(ret) yield ret break for key in DictMethods.iterkeys(self): if key not in seen: yield key
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'keys'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'block', 'children': ['6', '18', '24']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'list'},{'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': 'dict'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'keys'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '23']},{'id': '20', 'type': 'attribute', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'k'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '23', 'type': 'argument_list', 'children': []},{'id': '24', 'type': 'return_statement', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'k'}
def keys(self): k = list(dict.keys(self)) k.sort() return k
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_reports_page'},{'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': 'is_enclave'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'enclave_ids'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '13', 'type': 'None', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'excluded_tags'},{'id': '16', 'type': 'None', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'from_time'},{'id': '19', 'type': 'None', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'to_time'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '28', '47', '58', '80', '94', '110']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'assignment', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'distribution_type'},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'if_statement', 'children': ['29', '30', '37']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'is_enclave'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'expression_statement', 'children': ['32']},{'id': '32', 'type': 'assignment', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'distribution_type'},{'id': '34', 'type': 'attribute', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'DistributionType'},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'ENCLAVE'},{'id': '37', 'type': 'elif_clause', 'children': ['38', '40']},{'id': '38', 'type': 'not_operator', 'children': ['39']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'is_enclave'},{'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': 'distribution_type'},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'DistributionType'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'COMMUNITY'},{'id': '47', 'type': 'if_statement', 'children': ['48', '51']},{'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'enclave_ids'},{'id': '50', 'type': 'None', 'children': []},{'id': '51', 'type': 'block', 'children': ['52']},{'id': '52', 'type': 'expression_statement', 'children': ['53']},{'id': '53', 'type': 'assignment', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'enclave_ids'},{'id': '55', 'type': 'attribute', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'enclave_ids'},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '61', 'type': 'dictionary', 'children': ['62', '65', '68', '71', '74', '77']},{'id': '62', 'type': 'pair', 'children': ['63', '64']},{'id': '63', 'type': 'string', 'children': [], 'value': "'from'"},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'from_time'},{'id': '65', 'type': 'pair', 'children': ['66', '67']},{'id': '66', 'type': 'string', 'children': [], 'value': "'to'"},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'to_time'},{'id': '68', 'type': 'pair', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': "'distributionType'"},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'distribution_type'},{'id': '71', 'type': 'pair', 'children': ['72', '73']},{'id': '72', 'type': 'string', 'children': [], 'value': "'enclaveIds'"},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'enclave_ids'},{'id': '74', 'type': 'pair', 'children': ['75', '76']},{'id': '75', 'type': 'string', 'children': [], 'value': "'tags'"},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'tag'},{'id': '77', 'type': 'pair', 'children': ['78', '79']},{'id': '78', 'type': 'string', 'children': [], 'value': "'excludedTags'"},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'excluded_tags'},{'id': '80', 'type': 'expression_statement', 'children': ['81']},{'id': '81', 'type': 'assignment', 'children': ['82', '83']},{'id': '82', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '83', 'type': 'call', 'children': ['84', '89']},{'id': '84', 'type': 'attribute', 'children': ['85', '88']},{'id': '85', 'type': 'attribute', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '87', 'type': 'identifier', 'children': [], 'value': '_client'},{'id': '88', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '89', 'type': 'argument_list', 'children': ['90', '91']},{'id': '90', 'type': 'string', 'children': [], 'value': '"reports"'},{'id': '91', 'type': 'keyword_argument', 'children': ['92', '93']},{'id': '92', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '94', 'type': 'expression_statement', 'children': ['95']},{'id': '95', 'type': 'assignment', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'result'},{'id': '97', 'type': 'call', 'children': ['98', '101']},{'id': '98', 'type': 'attribute', 'children': ['99', '100']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'Page'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'from_dict'},{'id': '101', 'type': 'argument_list', 'children': ['102', '107']},{'id': '102', 'type': 'call', 'children': ['103', '106']},{'id': '103', 'type': 'attribute', 'children': ['104', '105']},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'resp'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'json'},{'id': '106', 'type': 'argument_list', 'children': []},{'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'content_type'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'Report'},{'id': '110', 'type': 'return_statement', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'result'}
def get_reports_page(self, is_enclave=None, enclave_ids=None, tag=None, excluded_tags=None, from_time=None, to_time=None): distribution_type = None if is_enclave: distribution_type = DistributionType.ENCLAVE elif not is_enclave: distribution_type = DistributionType.COMMUNITY if enclave_ids is None: enclave_ids = self.enclave_ids params = { 'from': from_time, 'to': to_time, 'distributionType': distribution_type, 'enclaveIds': enclave_ids, 'tags': tag, 'excludedTags': excluded_tags } resp = self._client.get("reports", params=params) result = Page.from_dict(resp.json(), content_type=Report) return result
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9', '11']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'hashify_targets'},{'id': '3', 'type': 'parameters', 'children': ['4', '8']},{'id': '4', 'type': 'typed_parameter', 'children': ['5', '6']},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'targets'},{'id': '6', 'type': 'type', 'children': ['7']},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'build_context'},{'id': '9', 'type': 'type', 'children': ['10']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'return_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '15', 'type': 'generator_expression', 'children': ['16', '26']},{'id': '16', 'type': 'call', 'children': ['17', '24']},{'id': '17', 'type': 'attribute', 'children': ['18', '23']},{'id': '18', 'type': 'subscript', 'children': ['19', '22']},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'build_context'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'targets'},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'target_name'},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'hash'},{'id': '24', 'type': 'argument_list', 'children': ['25']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'build_context'},{'id': '26', 'type': 'for_in_clause', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'target_name'},{'id': '28', 'type': 'call', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'listify'},{'id': '30', 'type': 'argument_list', 'children': ['31']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'targets'}
def hashify_targets(targets: list, build_context) -> list: return sorted(build_context.targets[target_name].hash(build_context) for target_name in listify(targets))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'stable_reverse_topological_sort'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '5', 'type': 'block', 'children': ['6', '21', '27', '33']},{'id': '6', 'type': 'if_statement', 'children': ['7', '13']},{'id': '7', 'type': 'not_operator', 'children': ['8']},{'id': '8', 'type': 'call', 'children': ['9', '12']},{'id': '9', 'type': 'attribute', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'is_directed'},{'id': '12', 'type': 'argument_list', 'children': []},{'id': '13', 'type': 'block', 'children': ['14']},{'id': '14', 'type': 'raise_statement', 'children': ['15']},{'id': '15', 'type': 'call', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'networkx'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'NetworkXError'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'string', 'children': [], 'value': "'Topological sort not defined on undirected graphs.'"},{'id': '21', 'type': 'expression_statement', 'children': ['22']},{'id': '22', 'type': 'assignment', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '26', 'type': 'argument_list', 'children': []},{'id': '27', 'type': 'expression_statement', 'children': ['28']},{'id': '28', 'type': 'assignment', 'children': ['29', '30']},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'explored'},{'id': '30', 'type': 'call', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '32', 'type': 'argument_list', 'children': []},{'id': '33', 'type': 'for_statement', 'children': ['34', '35', '43']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '35', 'type': 'call', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '37', 'type': 'argument_list', 'children': ['38']},{'id': '38', 'type': 'call', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'nodes'},{'id': '42', 'type': 'argument_list', 'children': []},{'id': '43', 'type': 'block', 'children': ['44', '50', '55']},{'id': '44', 'type': 'if_statement', 'children': ['45', '48']},{'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': 'in'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '47', 'type': 'identifier', 'children': [], 'value': 'explored'},{'id': '48', 'type': 'block', 'children': ['49']},{'id': '49', 'type': 'continue_statement', 'children': []},{'id': '50', 'type': 'expression_statement', 'children': ['51']},{'id': '51', 'type': 'assignment', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '53', 'type': 'list', 'children': ['54'], 'value': '[v]'},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'v'},{'id': '55', 'type': 'while_statement', 'children': ['56', '57']},{'id': '56', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '57', 'type': 'block', 'children': ['58', '65', '77', '84', '88', '121']},{'id': '58', 'type': 'expression_statement', 'children': ['59']},{'id': '59', 'type': 'assignment', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '61', 'type': 'subscript', 'children': ['62', '63']},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '63', 'type': 'unary_operator', 'children': ['64'], 'value': '-'},{'id': '64', 'type': 'integer', 'children': [], 'value': '1'},{'id': '65', 'type': 'if_statement', 'children': ['66', '69']},{'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'in'},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'explored'},{'id': '69', 'type': 'block', 'children': ['70', '76']},{'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': 'fringe'},{'id': '74', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '75', 'type': 'argument_list', 'children': []},{'id': '76', 'type': 'continue_statement', 'children': []},{'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': 'seen'},{'id': '81', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '82', 'type': 'argument_list', 'children': ['83']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '84', 'type': 'expression_statement', 'children': ['85']},{'id': '85', 'type': 'assignment', 'children': ['86', '87']},{'id': '86', 'type': 'identifier', 'children': [], 'value': 'new_nodes'},{'id': '87', 'type': 'list', 'children': [], 'value': '[]'},{'id': '88', 'type': 'for_statement', 'children': ['89', '90', '96']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '90', 'type': 'call', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '92', 'type': 'argument_list', 'children': ['93']},{'id': '93', 'type': 'subscript', 'children': ['94', '95']},{'id': '94', 'type': 'identifier', 'children': [], 'value': 'graph'},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '96', 'type': 'block', 'children': ['97']},{'id': '97', 'type': 'if_statement', 'children': ['98', '101']},{'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'not'},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '100', 'type': 'identifier', 'children': [], 'value': 'explored'},{'id': '101', 'type': 'block', 'children': ['102', '114']},{'id': '102', 'type': 'if_statement', 'children': ['103', '106']},{'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'in'},{'id': '104', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '105', 'type': 'identifier', 'children': [], 'value': 'seen'},{'id': '106', 'type': 'block', 'children': ['107']},{'id': '107', 'type': 'raise_statement', 'children': ['108']},{'id': '108', 'type': 'call', 'children': ['109', '112']},{'id': '109', 'type': 'attribute', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'networkx'},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'NetworkXUnfeasible'},{'id': '112', 'type': 'argument_list', 'children': ['113']},{'id': '113', 'type': 'string', 'children': [], 'value': "'Graph contains a cycle.'"},{'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': 'new_nodes'},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '119', 'type': 'argument_list', 'children': ['120']},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'n'},{'id': '121', 'type': 'if_statement', 'children': ['122', '123', '131']},{'id': '122', 'type': 'identifier', 'children': [], 'value': 'new_nodes'},{'id': '123', 'type': 'block', 'children': ['124']},{'id': '124', 'type': 'expression_statement', 'children': ['125']},{'id': '125', 'type': 'call', 'children': ['126', '129']},{'id': '126', 'type': 'attribute', 'children': ['127', '128']},{'id': '127', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '128', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '129', 'type': 'argument_list', 'children': ['130']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'new_nodes'},{'id': '131', 'type': 'else_clause', 'children': ['132']},{'id': '132', 'type': 'block', 'children': ['133', '140', '143']},{'id': '133', 'type': 'expression_statement', 'children': ['134']},{'id': '134', 'type': 'call', 'children': ['135', '138']},{'id': '135', 'type': 'attribute', 'children': ['136', '137']},{'id': '136', 'type': 'identifier', 'children': [], 'value': 'explored'},{'id': '137', 'type': 'identifier', 'children': [], 'value': 'add'},{'id': '138', 'type': 'argument_list', 'children': ['139']},{'id': '139', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '140', 'type': 'expression_statement', 'children': ['141']},{'id': '141', 'type': 'yield', 'children': ['142']},{'id': '142', 'type': 'identifier', 'children': [], 'value': 'w'},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'call', 'children': ['145', '148']},{'id': '145', 'type': 'attribute', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'fringe'},{'id': '147', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '148', 'type': 'argument_list', 'children': []}
def stable_reverse_topological_sort(graph): if not graph.is_directed(): raise networkx.NetworkXError( 'Topological sort not defined on undirected graphs.') seen = set() explored = set() for v in sorted(graph.nodes()): if v in explored: continue fringe = [v] while fringe: w = fringe[-1] if w in explored: fringe.pop() continue seen.add(w) new_nodes = [] for n in sorted(graph[w]): if n not in explored: if n in seen: raise networkx.NetworkXUnfeasible( 'Graph contains a cycle.') new_nodes.append(n) if new_nodes: fringe.extend(new_nodes) else: explored.add(w) yield w fringe.pop()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'walk_target_deps_topological_order'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '7', 'type': 'type', 'children': ['8']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'Target'},{'id': '9', 'type': 'block', 'children': ['10', '22']},{'id': '10', 'type': 'expression_statement', 'children': ['11']},{'id': '11', 'type': 'assignment', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'all_deps'},{'id': '13', 'type': 'call', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_descendants'},{'id': '15', 'type': 'argument_list', 'children': ['16', '19']},{'id': '16', 'type': 'attribute', 'children': ['17', '18']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'target_graph'},{'id': '19', 'type': 'attribute', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'target'},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'name'},{'id': '22', 'type': 'for_statement', 'children': ['23', '24', '30']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'dep_name'},{'id': '24', 'type': 'call', 'children': ['25', '26']},{'id': '25', 'type': 'identifier', 'children': [], 'value': 'topological_sort'},{'id': '26', 'type': 'argument_list', 'children': ['27']},{'id': '27', 'type': 'attribute', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'target_graph'},{'id': '30', 'type': 'block', 'children': ['31']},{'id': '31', 'type': 'if_statement', 'children': ['32', '35']},{'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'in'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'dep_name'},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'all_deps'},{'id': '35', 'type': 'block', 'children': ['36']},{'id': '36', 'type': 'expression_statement', 'children': ['37']},{'id': '37', 'type': 'yield', 'children': ['38']},{'id': '38', 'type': 'subscript', 'children': ['39', '42']},{'id': '39', 'type': 'attribute', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'targets'},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'dep_name'}
def walk_target_deps_topological_order(self, target: Target): all_deps = get_descendants(self.target_graph, target.name) for dep_name in topological_sort(self.target_graph): if dep_name in all_deps: yield self.targets[dep_name]
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_print_message'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '7', 'type': 'default_parameter', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '9', 'type': 'True', 'children': []},{'id': '10', 'type': 'block', 'children': ['11', '13', '22', '273']},{'id': '11', 'type': 'expression_statement', 'children': ['12']},{'id': '12', 'type': 'string', 'children': [], 'value': "'Prints a message and takes care of all sorts of nasty code'"},{'id': '13', 'type': 'expression_statement', 'children': ['14']},{'id': '14', 'type': 'assignment', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '16', 'type': 'list', 'children': ['17', '18', '19'], 'value': "['\\n', prefix, message['message']]"},{'id': '17', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '19', 'type': 'subscript', 'children': ['20', '21']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '21', 'type': 'string', 'children': [], 'value': "'message'"},{'id': '22', 'type': 'if_statement', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'verbose'},{'id': '24', 'type': 'block', 'children': ['25', '29', '48', '68', '97', '108', '114', '175', '191', '213', '254', '261']},{'id': '25', 'type': 'expression_statement', 'children': ['26']},{'id': '26', 'type': 'assignment', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'verbose_output'},{'id': '28', 'type': 'list', 'children': [], 'value': '[]'},{'id': '29', 'type': 'if_statement', 'children': ['30', '33']},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '32', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '33', 'type': 'block', 'children': ['34']},{'id': '34', 'type': 'expression_statement', 'children': ['35']},{'id': '35', 'type': 'call', 'children': ['36', '39']},{'id': '36', 'type': 'attribute', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'verbose_output'},{'id': '38', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '39', 'type': 'argument_list', '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': '_flatten_list'},{'id': '44', 'type': 'argument_list', 'children': ['45']},{'id': '45', 'type': 'subscript', 'children': ['46', '47']},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '47', 'type': 'string', 'children': [], 'value': "'description'"},{'id': '48', 'type': 'if_statement', 'children': ['49', '55']},{'id': '49', 'type': 'call', 'children': ['50', '53']},{'id': '50', 'type': 'attribute', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '53', 'type': 'argument_list', 'children': ['54']},{'id': '54', 'type': 'string', 'children': [], 'value': "'signing_severity'"},{'id': '55', 'type': 'block', 'children': ['56']},{'id': '56', 'type': 'expression_statement', 'children': ['57']},{'id': '57', 'type': 'call', 'children': ['58', '61']},{'id': '58', 'type': 'attribute', 'children': ['59', '60']},{'id': '59', 'type': 'identifier', 'children': [], 'value': 'verbose_output'},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '61', 'type': 'argument_list', 'children': ['62']},{'id': '62', 'type': '()', 'children': ['63']},{'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '%'},{'id': '64', 'type': 'string', 'children': [], 'value': "'\\tAutomated signing severity: %s'"},{'id': '65', 'type': 'subscript', 'children': ['66', '67']},{'id': '66', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '67', 'type': 'string', 'children': [], 'value': "'signing_severity'"},{'id': '68', 'type': 'if_statement', 'children': ['69', '75']},{'id': '69', 'type': 'call', 'children': ['70', '73']},{'id': '70', 'type': 'attribute', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '73', 'type': 'argument_list', 'children': ['74']},{'id': '74', 'type': 'string', 'children': [], 'value': "'signing_help'"},{'id': '75', 'type': 'block', 'children': ['76', '83']},{'id': '76', 'type': 'expression_statement', 'children': ['77']},{'id': '77', 'type': 'call', 'children': ['78', '81']},{'id': '78', 'type': 'attribute', 'children': ['79', '80']},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'verbose_output'},{'id': '80', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '81', 'type': 'argument_list', 'children': ['82']},{'id': '82', 'type': 'string', 'children': [], 'value': "'\\tSuggestions for passing automated signing:'"},{'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': 'verbose_output'},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '88', 'type': 'argument_list', 'children': ['89']},{'id': '89', 'type': 'call', 'children': ['90', '93']},{'id': '90', 'type': 'attribute', 'children': ['91', '92']},{'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '92', 'type': 'identifier', 'children': [], 'value': '_flatten_list'},{'id': '93', 'type': 'argument_list', 'children': ['94']},{'id': '94', 'type': 'subscript', 'children': ['95', '96']},{'id': '95', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '96', 'type': 'string', 'children': [], 'value': "'signing_help'"},{'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': 'verbose_output'},{'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '102', 'type': 'argument_list', 'children': ['103']},{'id': '103', 'type': 'binary_operator', 'children': ['104', '105'], 'value': '%'},{'id': '104', 'type': 'string', 'children': [], 'value': "'\\tTier:\\t%d'"},{'id': '105', 'type': 'subscript', 'children': ['106', '107']},{'id': '106', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '107', 'type': 'string', 'children': [], 'value': "'tier'"},{'id': '108', 'type': 'expression_statement', 'children': ['109']},{'id': '109', 'type': 'assignment', 'children': ['110', '111']},{'id': '110', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '111', 'type': 'subscript', 'children': ['112', '113']},{'id': '112', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '113', 'type': 'string', 'children': [], 'value': "'file'"},{'id': '114', 'type': 'if_statement', 'children': ['115', '122']},{'id': '115', 'type': 'boolean_operator', 'children': ['116', '119'], 'value': 'and'},{'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'is'},{'id': '117', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '118', 'type': 'None', 'children': []},{'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': '!='},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '121', 'type': 'string', 'children': [], 'value': "''"},{'id': '122', 'type': 'block', 'children': ['123', '127']},{'id': '123', 'type': 'expression_statement', 'children': ['124']},{'id': '124', 'type': 'assignment', 'children': ['125', '126']},{'id': '125', 'type': 'identifier', 'children': [], 'value': 'fmsg'},{'id': '126', 'type': 'string', 'children': [], 'value': "'\\tFile:\\t%s'"},{'id': '127', 'type': 'if_statement', 'children': ['128', '134', '164']},{'id': '128', 'type': 'comparison_operator', 'children': ['129', '133'], 'value': 'is'},{'id': '129', 'type': 'call', 'children': ['130', '131']},{'id': '130', 'type': 'identifier', 'children': [], 'value': 'type'},{'id': '131', 'type': 'argument_list', 'children': ['132']},{'id': '132', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '133', 'type': 'identifier', 'children': [], 'value': 'list'},{'id': '134', 'type': 'block', 'children': ['135', '150']},{'id': '135', 'type': 'if_statement', 'children': ['136', '142']},{'id': '136', 'type': 'comparison_operator', 'children': ['137', '141'], 'value': '=='},{'id': '137', 'type': 'subscript', 'children': ['138', '139']},{'id': '138', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '139', 'type': 'unary_operator', 'children': ['140'], 'value': '-'},{'id': '140', 'type': 'integer', 'children': [], 'value': '1'},{'id': '141', 'type': 'string', 'children': [], 'value': "''"},{'id': '142', 'type': 'block', 'children': ['143']},{'id': '143', 'type': 'expression_statement', 'children': ['144']},{'id': '144', 'type': 'assignment', 'children': ['145', '149']},{'id': '145', 'type': 'subscript', 'children': ['146', '147']},{'id': '146', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '147', 'type': 'unary_operator', 'children': ['148'], 'value': '-'},{'id': '148', 'type': 'integer', 'children': [], 'value': '1'},{'id': '149', 'type': 'string', 'children': [], 'value': "'(none)'"},{'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': 'verbose_output'},{'id': '154', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '155', 'type': 'argument_list', 'children': ['156']},{'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '%'},{'id': '157', 'type': 'identifier', 'children': [], 'value': 'fmsg'},{'id': '158', 'type': 'call', 'children': ['159', '162']},{'id': '159', 'type': 'attribute', 'children': ['160', '161']},{'id': '160', 'type': 'string', 'children': [], 'value': "' > '"},{'id': '161', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '162', 'type': 'argument_list', 'children': ['163']},{'id': '163', 'type': 'identifier', 'children': [], 'value': 'files'},{'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': 'verbose_output'},{'id': '170', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '171', 'type': 'argument_list', 'children': ['172']},{'id': '172', 'type': 'binary_operator', 'children': ['173', '174'], 'value': '%'},{'id': '173', 'type': 'identifier', 'children': [], 'value': 'fmsg'},{'id': '174', 'type': 'identifier', 'children': [], 'value': 'files'},{'id': '175', 'type': 'if_statement', 'children': ['176', '179']},{'id': '176', 'type': 'subscript', 'children': ['177', '178']},{'id': '177', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '178', 'type': 'string', 'children': [], 'value': "'line'"},{'id': '179', 'type': 'block', 'children': ['180']},{'id': '180', 'type': 'expression_statement', 'children': ['181']},{'id': '181', 'type': 'call', 'children': ['182', '185']},{'id': '182', 'type': 'attribute', 'children': ['183', '184']},{'id': '183', 'type': 'identifier', 'children': [], 'value': 'verbose_output'},{'id': '184', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '185', 'type': 'argument_list', 'children': ['186']},{'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '%'},{'id': '187', 'type': 'string', 'children': [], 'value': "'\\tLine:\\t%s'"},{'id': '188', 'type': 'subscript', 'children': ['189', '190']},{'id': '189', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '190', 'type': 'string', 'children': [], 'value': "'line'"},{'id': '191', 'type': 'if_statement', 'children': ['192', '201']},{'id': '192', 'type': 'boolean_operator', 'children': ['193', '196'], 'value': 'and'},{'id': '193', 'type': 'subscript', 'children': ['194', '195']},{'id': '194', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '195', 'type': 'string', 'children': [], 'value': "'column'"},{'id': '196', 'type': 'comparison_operator', 'children': ['197', '200'], 'value': '!='},{'id': '197', 'type': 'subscript', 'children': ['198', '199']},{'id': '198', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '199', 'type': 'string', 'children': [], 'value': "'column'"},{'id': '200', 'type': 'integer', 'children': [], 'value': '0'},{'id': '201', 'type': 'block', 'children': ['202']},{'id': '202', 'type': 'expression_statement', 'children': ['203']},{'id': '203', 'type': 'call', 'children': ['204', '207']},{'id': '204', 'type': 'attribute', 'children': ['205', '206']},{'id': '205', 'type': 'identifier', 'children': [], 'value': 'verbose_output'},{'id': '206', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '207', 'type': 'argument_list', 'children': ['208']},{'id': '208', 'type': 'binary_operator', 'children': ['209', '210'], 'value': '%'},{'id': '209', 'type': 'string', 'children': [], 'value': "'\\tColumn:\\t%d'"},{'id': '210', 'type': 'subscript', 'children': ['211', '212']},{'id': '211', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '212', 'type': 'string', 'children': [], 'value': "'column'"},{'id': '213', 'type': 'if_statement', 'children': ['214', '220']},{'id': '214', 'type': 'call', 'children': ['215', '218']},{'id': '215', 'type': 'attribute', 'children': ['216', '217']},{'id': '216', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '217', 'type': 'identifier', 'children': [], 'value': 'get'},{'id': '218', 'type': 'argument_list', 'children': ['219']},{'id': '219', 'type': 'string', 'children': [], 'value': "'context'"},{'id': '220', 'type': 'block', 'children': ['221', '228']},{'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': 'verbose_output'},{'id': '225', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '226', 'type': 'argument_list', 'children': ['227']},{'id': '227', 'type': 'string', 'children': [], 'value': "'\\tContext:'"},{'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': 'verbose_output'},{'id': '232', 'type': 'identifier', 'children': [], 'value': 'extend'},{'id': '233', 'type': 'argument_list', 'children': ['234']},{'id': '234', 'type': 'list_comprehension', 'children': ['235', '249']},{'id': '235', 'type': '()', 'children': ['236']},{'id': '236', 'type': 'conditional_expression', 'children': ['237', '240', '243'], 'value': 'if'},{'id': '237', 'type': 'binary_operator', 'children': ['238', '239'], 'value': '%'},{'id': '238', 'type': 'string', 'children': [], 'value': "'\\t> %s'"},{'id': '239', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '240', 'type': 'comparison_operator', 'children': ['241', '242'], 'value': 'is'},{'id': '241', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '242', 'type': 'None', 'children': []},{'id': '243', 'type': 'binary_operator', 'children': ['244', '245'], 'value': '+'},{'id': '244', 'type': 'string', 'children': [], 'value': "'\\t>'"},{'id': '245', 'type': '()', 'children': ['246']},{'id': '246', 'type': 'binary_operator', 'children': ['247', '248'], 'value': '*'},{'id': '247', 'type': 'string', 'children': [], 'value': "'-'"},{'id': '248', 'type': 'integer', 'children': [], 'value': '20'},{'id': '249', 'type': 'for_in_clause', 'children': ['250', '251']},{'id': '250', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '251', 'type': 'subscript', 'children': ['252', '253']},{'id': '252', 'type': 'identifier', 'children': [], 'value': 'message'},{'id': '253', 'type': 'string', 'children': [], 'value': "'context'"},{'id': '254', 'type': 'expression_statement', 'children': ['255']},{'id': '255', 'type': 'call', 'children': ['256', '259']},{'id': '256', 'type': 'attribute', 'children': ['257', '258']},{'id': '257', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '258', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '259', 'type': 'argument_list', 'children': ['260']},{'id': '260', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '261', 'type': 'expression_statement', 'children': ['262']},{'id': '262', 'type': 'call', 'children': ['263', '266']},{'id': '263', 'type': 'attribute', 'children': ['264', '265']},{'id': '264', 'type': 'identifier', 'children': [], 'value': 'output'},{'id': '265', 'type': 'identifier', 'children': [], 'value': 'append'},{'id': '266', 'type': 'argument_list', 'children': ['267']},{'id': '267', 'type': 'call', 'children': ['268', '271']},{'id': '268', 'type': 'attribute', 'children': ['269', '270']},{'id': '269', 'type': 'string', 'children': [], 'value': "'\\n'"},{'id': '270', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '271', 'type': 'argument_list', 'children': ['272']},{'id': '272', 'type': 'identifier', 'children': [], 'value': 'verbose_output'},{'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': 'self'},{'id': '278', 'type': 'identifier', 'children': [], 'value': 'handler'},{'id': '279', 'type': 'identifier', 'children': [], 'value': 'write'},{'id': '280', 'type': 'argument_list', 'children': ['281']},{'id': '281', 'type': 'call', 'children': ['282', '285']},{'id': '282', 'type': 'attribute', 'children': ['283', '284']},{'id': '283', 'type': 'string', 'children': [], 'value': "u''"},{'id': '284', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '285', 'type': 'argument_list', 'children': ['286']},{'id': '286', 'type': 'call', 'children': ['287', '288']},{'id': '287', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '288', 'type': 'argument_list', 'children': ['289', '292']},{'id': '289', 'type': 'attribute', 'children': ['290', '291']},{'id': '290', 'type': 'identifier', 'children': [], 'value': 'unicodehelper'},{'id': '291', 'type': 'identifier', 'children': [], 'value': 'decode'},{'id': '292', 'type': 'identifier', 'children': [], 'value': 'output'}
def _print_message(self, prefix, message, verbose=True): 'Prints a message and takes care of all sorts of nasty code' output = ['\n', prefix, message['message']] if verbose: verbose_output = [] if message['description']: verbose_output.append( self._flatten_list(message['description'])) if message.get('signing_severity'): verbose_output.append( ('\tAutomated signing severity: %s' % message['signing_severity'])) if message.get('signing_help'): verbose_output.append( '\tSuggestions for passing automated signing:') verbose_output.append( self._flatten_list(message['signing_help'])) verbose_output.append('\tTier:\t%d' % message['tier']) files = message['file'] if files is not None and files != '': fmsg = '\tFile:\t%s' if type(files) is list: if files[-1] == '': files[-1] = '(none)' verbose_output.append(fmsg % ' > '.join(files)) else: verbose_output.append(fmsg % files) if message['line']: verbose_output.append('\tLine:\t%s' % message['line']) if message['column'] and message['column'] != 0: verbose_output.append('\tColumn:\t%d' % message['column']) if message.get('context'): verbose_output.append('\tContext:') verbose_output.extend([('\t> %s' % x if x is not None else '\t>' + ('-' * 20)) for x in message['context']]) output.append('\n') output.append('\n'.join(verbose_output)) self.handler.write(u''.join(map(unicodehelper.decode, output)))
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'finish'},{'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': 'items'},{'id': '7', 'type': 'None', 'children': []},{'id': '8', 'type': 'default_parameter', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'sort_methods'},{'id': '10', 'type': 'None', 'children': []},{'id': '11', 'type': 'default_parameter', 'children': ['12', '13']},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'succeeded'},{'id': '13', 'type': 'True', 'children': []},{'id': '14', 'type': 'default_parameter', 'children': ['15', '16']},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'update_listing'},{'id': '16', 'type': 'False', 'children': []},{'id': '17', 'type': 'default_parameter', 'children': ['18', '19']},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'cache_to_disc'},{'id': '19', 'type': 'True', 'children': []},{'id': '20', 'type': 'default_parameter', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'view_mode'},{'id': '22', 'type': 'None', 'children': []},{'id': '23', 'type': 'block', 'children': ['24', '26', '36', '74', '112', '121']},{'id': '24', 'type': 'expression_statement', 'children': ['25']},{'id': '25', 'type': 'string', 'children': [], 'value': "'''Adds the provided items to the XBMC interface.\n :param items: an iterable of items where each item is either a\n dictionary with keys/values suitable for passing to\n :meth:`xbmcswift2.ListItem.from_dict` or an instance of\n :class:`xbmcswift2.ListItem`.\n :param sort_methods: a list of valid XBMC sort_methods. Each item in\n the list can either be a sort method or a tuple of\n ``sort_method, label2_mask``. See\n :meth:`add_sort_method` for\n more detail concerning valid sort_methods.\n Example call with sort_methods::\n sort_methods = ['label', 'title', ('date', '%D')]\n plugin.finish(items, sort_methods=sort_methods)\n :param view_mode: can either be an integer (or parseable integer\n string) corresponding to a view_mode or the name of a type of view.\n Currrently the only view type supported is 'thumbnail'.\n :returns: a list of all ListItems added to the XBMC interface.\n '''"},{'id': '26', 'type': 'if_statement', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'items'},{'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': 'self'},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'add_items'},{'id': '34', 'type': 'argument_list', 'children': ['35']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'items'},{'id': '36', 'type': 'if_statement', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'sort_methods'},{'id': '38', 'type': 'block', 'children': ['39']},{'id': '39', 'type': 'for_statement', 'children': ['40', '41', '42']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'sort_method'},{'id': '41', 'type': 'identifier', 'children': [], 'value': 'sort_methods'},{'id': '42', 'type': 'block', 'children': ['43']},{'id': '43', 'type': 'if_statement', 'children': ['44', '56', '65']},{'id': '44', 'type': 'boolean_operator', 'children': ['45', '51'], 'value': 'and'},{'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': 'sort_method'},{'id': '50', 'type': 'identifier', 'children': [], 'value': 'basestring'},{'id': '51', 'type': 'call', 'children': ['52', '53']},{'id': '52', 'type': 'identifier', 'children': [], 'value': 'hasattr'},{'id': '53', 'type': 'argument_list', 'children': ['54', '55']},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'sort_method'},{'id': '55', 'type': 'string', 'children': [], 'value': "'__len__'"},{'id': '56', 'type': 'block', 'children': ['57']},{'id': '57', 'type': 'expression_statement', 'children': ['58']},{'id': '58', 'type': 'call', 'children': ['59', '62']},{'id': '59', 'type': 'attribute', 'children': ['60', '61']},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '61', 'type': 'identifier', 'children': [], 'value': 'add_sort_method'},{'id': '62', 'type': 'argument_list', 'children': ['63']},{'id': '63', 'type': 'list_splat', 'children': ['64']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'sort_method'},{'id': '65', 'type': 'else_clause', 'children': ['66']},{'id': '66', 'type': 'block', 'children': ['67']},{'id': '67', 'type': 'expression_statement', 'children': ['68']},{'id': '68', 'type': 'call', 'children': ['69', '72']},{'id': '69', 'type': 'attribute', 'children': ['70', '71']},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'add_sort_method'},{'id': '72', 'type': 'argument_list', 'children': ['73']},{'id': '73', 'type': 'identifier', 'children': [], 'value': 'sort_method'},{'id': '74', 'type': 'if_statement', 'children': ['75', '78']},{'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'},{'id': '76', 'type': 'identifier', 'children': [], 'value': 'view_mode'},{'id': '77', 'type': 'None', 'children': []},{'id': '78', 'type': 'block', 'children': ['79', '100']},{'id': '79', 'type': 'try_statement', 'children': ['80', '88']},{'id': '80', 'type': 'block', 'children': ['81']},{'id': '81', 'type': 'expression_statement', 'children': ['82']},{'id': '82', 'type': 'assignment', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'view_mode_id'},{'id': '84', 'type': 'call', 'children': ['85', '86']},{'id': '85', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '86', 'type': 'argument_list', 'children': ['87']},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'view_mode'},{'id': '88', 'type': 'except_clause', 'children': ['89', '90']},{'id': '89', 'type': 'identifier', 'children': [], 'value': 'ValueError'},{'id': '90', 'type': 'block', 'children': ['91']},{'id': '91', 'type': 'expression_statement', 'children': ['92']},{'id': '92', 'type': 'assignment', 'children': ['93', '94']},{'id': '93', 'type': 'identifier', 'children': [], 'value': 'view_mode_id'},{'id': '94', 'type': 'call', 'children': ['95', '98']},{'id': '95', 'type': 'attribute', 'children': ['96', '97']},{'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '97', 'type': 'identifier', 'children': [], 'value': 'get_view_mode_id'},{'id': '98', 'type': 'argument_list', 'children': ['99']},{'id': '99', 'type': 'identifier', 'children': [], 'value': 'view_mode'},{'id': '100', 'type': 'if_statement', 'children': ['101', '104']},{'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'is'},{'id': '102', 'type': 'identifier', 'children': [], 'value': 'view_mode_id'},{'id': '103', 'type': 'None', 'children': []},{'id': '104', 'type': 'block', 'children': ['105']},{'id': '105', 'type': 'expression_statement', 'children': ['106']},{'id': '106', 'type': 'call', 'children': ['107', '110']},{'id': '107', 'type': 'attribute', 'children': ['108', '109']},{'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '109', 'type': 'identifier', 'children': [], 'value': 'set_view_mode'},{'id': '110', 'type': 'argument_list', 'children': ['111']},{'id': '111', 'type': 'identifier', 'children': [], 'value': 'view_mode_id'},{'id': '112', 'type': 'expression_statement', 'children': ['113']},{'id': '113', 'type': 'call', 'children': ['114', '117']},{'id': '114', 'type': 'attribute', 'children': ['115', '116']},{'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '116', 'type': 'identifier', 'children': [], 'value': 'end_of_directory'},{'id': '117', 'type': 'argument_list', 'children': ['118', '119', '120']},{'id': '118', 'type': 'identifier', 'children': [], 'value': 'succeeded'},{'id': '119', 'type': 'identifier', 'children': [], 'value': 'update_listing'},{'id': '120', 'type': 'identifier', 'children': [], 'value': 'cache_to_disc'},{'id': '121', 'type': 'return_statement', 'children': ['122']},{'id': '122', 'type': 'attribute', 'children': ['123', '124']},{'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '124', 'type': 'identifier', 'children': [], 'value': 'added_items'}
def finish(self, items=None, sort_methods=None, succeeded=True, update_listing=False, cache_to_disc=True, view_mode=None): '''Adds the provided items to the XBMC interface. :param items: an iterable of items where each item is either a dictionary with keys/values suitable for passing to :meth:`xbmcswift2.ListItem.from_dict` or an instance of :class:`xbmcswift2.ListItem`. :param sort_methods: a list of valid XBMC sort_methods. Each item in the list can either be a sort method or a tuple of ``sort_method, label2_mask``. See :meth:`add_sort_method` for more detail concerning valid sort_methods. Example call with sort_methods:: sort_methods = ['label', 'title', ('date', '%D')] plugin.finish(items, sort_methods=sort_methods) :param view_mode: can either be an integer (or parseable integer string) corresponding to a view_mode or the name of a type of view. Currrently the only view type supported is 'thumbnail'. :returns: a list of all ListItems added to the XBMC interface. ''' if items: self.add_items(items) if sort_methods: for sort_method in sort_methods: if not isinstance(sort_method, basestring) and hasattr(sort_method, '__len__'): self.add_sort_method(*sort_method) else: self.add_sort_method(sort_method) if view_mode is not None: try: view_mode_id = int(view_mode) except ValueError: view_mode_id = self.get_view_mode_id(view_mode) if view_mode_id is not None: self.set_view_mode(view_mode_id) self.end_of_directory(succeeded, update_listing, cache_to_disc) return self.added_items
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'followingPrefix'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '5', 'type': 'block', 'children': ['6', '14', '23', '41', '49', '64', '74']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'prefixBytes'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '11', 'type': 'argument_list', 'children': ['12', '13']},{'id': '12', 'type': 'string', 'children': [], 'value': "'B'"},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '14', 'type': 'expression_statement', 'children': ['15']},{'id': '15', 'type': 'assignment', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'changeIndex'},{'id': '17', 'type': 'binary_operator', 'children': ['18', '22'], 'value': '-'},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'},{'id': '20', 'type': 'argument_list', 'children': ['21']},{'id': '21', 'type': 'identifier', 'children': [], 'value': 'prefixBytes'},{'id': '22', 'type': 'integer', 'children': [], 'value': '1'},{'id': '23', 'type': 'while_statement', 'children': ['24', '34']},{'id': '24', 'type': '()', 'children': ['25']},{'id': '25', 'type': 'boolean_operator', 'children': ['26', '29'], 'value': 'and'},{'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '>='},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'changeIndex'},{'id': '28', 'type': 'integer', 'children': [], 'value': '0'},{'id': '29', 'type': 'comparison_operator', 'children': ['30', '33'], 'value': '=='},{'id': '30', 'type': 'subscript', 'children': ['31', '32']},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'prefixBytes'},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'changeIndex'},{'id': '33', 'type': 'integer', 'children': [], 'value': '0xff'},{'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': 'changeIndex'},{'id': '38', 'type': 'binary_operator', 'children': ['39', '40'], 'value': '-'},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'changeIndex'},{'id': '40', 'type': 'integer', 'children': [], 'value': '1'},{'id': '41', 'type': 'if_statement', 'children': ['42', '46']},{'id': '42', 'type': '()', 'children': ['43']},{'id': '43', 'type': 'comparison_operator', 'children': ['44', '45'], 'value': '<'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'changeIndex'},{'id': '45', 'type': 'integer', 'children': [], 'value': '0'},{'id': '46', 'type': 'block', 'children': ['47']},{'id': '47', 'type': 'return_statement', 'children': ['48']},{'id': '48', 'type': 'None', 'children': []},{'id': '49', 'type': 'expression_statement', 'children': ['50']},{'id': '50', 'type': 'assignment', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'newBytes'},{'id': '52', 'type': 'call', 'children': ['53', '54']},{'id': '53', 'type': 'identifier', 'children': [], 'value': 'array'},{'id': '54', 'type': 'argument_list', 'children': ['55', '56']},{'id': '55', 'type': 'string', 'children': [], 'value': "'B'"},{'id': '56', 'type': 'subscript', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'prefix'},{'id': '58', 'type': 'slice', 'children': ['59', '60', '61']},{'id': '59', 'type': 'integer', 'children': [], 'value': '0'},{'id': '60', 'type': 'colon', 'children': []},{'id': '61', 'type': 'binary_operator', 'children': ['62', '63'], 'value': '+'},{'id': '62', 'type': 'identifier', 'children': [], 'value': 'changeIndex'},{'id': '63', 'type': 'integer', 'children': [], 'value': '1'},{'id': '64', 'type': 'expression_statement', 'children': ['65']},{'id': '65', 'type': 'assignment', 'children': ['66', '69']},{'id': '66', 'type': 'subscript', 'children': ['67', '68']},{'id': '67', 'type': 'identifier', 'children': [], 'value': 'newBytes'},{'id': '68', 'type': 'identifier', 'children': [], 'value': 'changeIndex'},{'id': '69', 'type': 'binary_operator', 'children': ['70', '73'], 'value': '+'},{'id': '70', 'type': 'subscript', 'children': ['71', '72']},{'id': '71', 'type': 'identifier', 'children': [], 'value': 'newBytes'},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'changeIndex'},{'id': '73', 'type': 'integer', 'children': [], 'value': '1'},{'id': '74', 'type': 'return_statement', 'children': ['75']},{'id': '75', 'type': 'call', 'children': ['76', '79']},{'id': '76', 'type': 'attribute', 'children': ['77', '78']},{'id': '77', 'type': 'identifier', 'children': [], 'value': 'newBytes'},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'tostring'},{'id': '79', 'type': 'argument_list', 'children': []}
def followingPrefix(prefix): prefixBytes = array('B', prefix) changeIndex = len(prefixBytes) - 1 while (changeIndex >= 0 and prefixBytes[changeIndex] == 0xff ): changeIndex = changeIndex - 1; if(changeIndex < 0): return None newBytes = array('B', prefix[0:changeIndex + 1]) newBytes[changeIndex] = newBytes[changeIndex] + 1 return newBytes.tostring()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sorted_maybe_numeric'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '5', 'type': 'block', 'children': ['6', '19']},{'id': '6', 'type': 'expression_statement', 'children': ['7']},{'id': '7', 'type': 'assignment', 'children': ['8', '9']},{'id': '8', 'type': 'identifier', 'children': [], 'value': 'all_numeric'},{'id': '9', 'type': 'call', 'children': ['10', '11']},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'all'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'call', 'children': ['13', '14']},{'id': '13', 'type': 'identifier', 'children': [], 'value': 'map'},{'id': '14', 'type': 'argument_list', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'isdigit'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '19', 'type': 'if_statement', 'children': ['20', '21', '30']},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'all_numeric'},{'id': '21', 'type': 'block', 'children': ['22']},{'id': '22', 'type': 'return_statement', 'children': ['23']},{'id': '23', 'type': 'call', 'children': ['24', '25']},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'identifier', 'children': [], 'value': 'x'},{'id': '27', 'type': 'keyword_argument', 'children': ['28', '29']},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'int'},{'id': '30', 'type': 'else_clause', 'children': ['31']},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'return_statement', 'children': ['33']},{'id': '33', 'type': 'call', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '35', 'type': 'argument_list', 'children': ['36']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'x'}
def sorted_maybe_numeric(x): all_numeric = all(map(str.isdigit, x)) if all_numeric: return sorted(x, key=int) else: return sorted(x)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'sf'},{'id': '6', 'type': 'block', 'children': ['7', '20']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'params'},{'id': '10', 'type': 'call', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'join_params'},{'id': '12', 'type': 'argument_list', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'parameters'},{'id': '16', 'type': 'dictionary', 'children': ['17']},{'id': '17', 'type': 'pair', 'children': ['18', '19']},{'id': '18', 'type': 'string', 'children': [], 'value': '"sf"'},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'sf'},{'id': '20', 'type': 'return_statement', 'children': ['21']},{'id': '21', 'type': 'call', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '24', 'type': 'identifier', 'children': [], 'value': '__class__'},{'id': '25', 'type': 'argument_list', 'children': ['26']},{'id': '26', 'type': 'dictionary_splat', 'children': ['27']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'params'}
def sort_by(self, sf): params = join_params(self.parameters, {"sf": sf}) return self.__class__(**params)
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_contributor_sort_value'},{'id': '3', 'type': 'parameters', 'children': ['4', '5']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '6', 'type': 'block', 'children': ['7', '13', '38']},{'id': '7', 'type': 'expression_statement', 'children': ['8']},{'id': '8', 'type': 'assignment', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '10', 'type': 'attribute', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'obj'},{'id': '12', 'type': 'identifier', 'children': [], 'value': 'contributor'},{'id': '13', 'type': 'if_statement', 'children': ['14', '21', '30']},{'id': '14', 'type': 'boolean_operator', 'children': ['15', '18'], 'value': 'or'},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'first_name'},{'id': '18', 'type': 'attribute', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '20', 'type': 'identifier', 'children': [], 'value': 'last_name'},{'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': 'contributor'},{'id': '25', 'type': 'call', 'children': ['26', '29']},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_full_name'},{'id': '29', 'type': 'argument_list', 'children': []},{'id': '30', 'type': 'else_clause', 'children': ['31']},{'id': '31', 'type': 'block', 'children': ['32']},{'id': '32', 'type': 'expression_statement', 'children': ['33']},{'id': '33', 'type': 'assignment', 'children': ['34', '35']},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'contributor'},{'id': '35', 'type': 'attribute', 'children': ['36', '37']},{'id': '36', 'type': 'identifier', 'children': [], 'value': 'user'},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'username'},{'id': '38', 'type': 'return_statement', 'children': ['39']},{'id': '39', 'type': 'call', 'children': ['40', '47']},{'id': '40', 'type': 'attribute', 'children': ['41', '46']},{'id': '41', 'type': 'call', 'children': ['42', '45']},{'id': '42', 'type': 'attribute', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': 'contributor'},{'id': '44', 'type': 'identifier', 'children': [], 'value': 'strip'},{'id': '45', 'type': 'argument_list', 'children': []},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'lower'},{'id': '47', 'type': 'argument_list', 'children': []}
def get_contributor_sort_value(self, obj): user = obj.contributor if user.first_name or user.last_name: contributor = user.get_full_name() else: contributor = user.username return contributor.strip().lower()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']},{'id': '2', 'type': 'function_name', 'children': [], 'value': '_gen_cache_key_for_slice'},{'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'url_dict'},{'id': '5', 'type': 'identifier', 'children': [], 'value': 'start_int'},{'id': '6', 'type': 'identifier', 'children': [], 'value': 'total_int'},{'id': '7', 'type': 'identifier', 'children': [], 'value': 'authn_subj_list'},{'id': '8', 'type': 'block', 'children': ['9', '18', '28', '38', '61', '73']},{'id': '9', 'type': 'expression_statement', 'children': ['10']},{'id': '10', 'type': 'assignment', 'children': ['11', '12']},{'id': '11', 'type': 'identifier', 'children': [], 'value': 'key_url_dict'},{'id': '12', 'type': 'call', 'children': ['13', '16']},{'id': '13', 'type': 'attribute', 'children': ['14', '15']},{'id': '14', 'type': 'identifier', 'children': [], 'value': 'copy'},{'id': '15', 'type': 'identifier', 'children': [], 'value': 'deepcopy'},{'id': '16', 'type': 'argument_list', 'children': ['17']},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'url_dict'},{'id': '18', 'type': 'expression_statement', 'children': ['19']},{'id': '19', 'type': 'call', 'children': ['20', '25']},{'id': '20', 'type': 'attribute', 'children': ['21', '24']},{'id': '21', 'type': 'subscript', 'children': ['22', '23']},{'id': '22', 'type': 'identifier', 'children': [], 'value': 'key_url_dict'},{'id': '23', 'type': 'string', 'children': [], 'value': "'query'"},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '25', 'type': 'argument_list', 'children': ['26', '27']},{'id': '26', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '27', 'type': 'None', 'children': []},{'id': '28', 'type': 'expression_statement', 'children': ['29']},{'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': 'key_url_dict'},{'id': '33', 'type': 'string', 'children': [], 'value': "'query'"},{'id': '34', 'type': 'identifier', 'children': [], 'value': 'pop'},{'id': '35', 'type': 'argument_list', 'children': ['36', '37']},{'id': '36', 'type': 'string', 'children': [], 'value': "'count'"},{'id': '37', 'type': 'None', 'children': []},{'id': '38', 'type': 'expression_statement', 'children': ['39']},{'id': '39', 'type': 'assignment', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'key_json'},{'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': 'd1_common'},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'util'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'serialize_to_normalized_compact_json'},{'id': '47', 'type': 'argument_list', 'children': ['48']},{'id': '48', 'type': 'dictionary', 'children': ['49', '52', '55', '58']},{'id': '49', 'type': 'pair', 'children': ['50', '51']},{'id': '50', 'type': 'string', 'children': [], 'value': "'url_dict'"},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'key_url_dict'},{'id': '52', 'type': 'pair', 'children': ['53', '54']},{'id': '53', 'type': 'string', 'children': [], 'value': "'start'"},{'id': '54', 'type': 'identifier', 'children': [], 'value': 'start_int'},{'id': '55', 'type': 'pair', 'children': ['56', '57']},{'id': '56', 'type': 'string', 'children': [], 'value': "'total'"},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'total_int'},{'id': '58', 'type': 'pair', 'children': ['59', '60']},{'id': '59', 'type': 'string', 'children': [], 'value': "'subject'"},{'id': '60', 'type': 'identifier', 'children': [], 'value': 'authn_subj_list'},{'id': '61', 'type': 'expression_statement', 'children': ['62']},{'id': '62', 'type': 'call', 'children': ['63', '66']},{'id': '63', 'type': 'attribute', 'children': ['64', '65']},{'id': '64', 'type': 'identifier', 'children': [], 'value': 'logging'},{'id': '65', 'type': 'identifier', 'children': [], 'value': 'debug'},{'id': '66', 'type': 'argument_list', 'children': ['67']},{'id': '67', 'type': 'call', 'children': ['68', '71']},{'id': '68', 'type': 'attribute', 'children': ['69', '70']},{'id': '69', 'type': 'string', 'children': [], 'value': "'key_json={}'"},{'id': '70', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '71', 'type': 'argument_list', 'children': ['72']},{'id': '72', 'type': 'identifier', 'children': [], 'value': 'key_json'},{'id': '73', 'type': 'return_statement', 'children': ['74']},{'id': '74', 'type': 'call', 'children': ['75', '88']},{'id': '75', 'type': 'attribute', 'children': ['76', '87']},{'id': '76', 'type': 'call', 'children': ['77', '80']},{'id': '77', 'type': 'attribute', 'children': ['78', '79']},{'id': '78', 'type': 'identifier', 'children': [], 'value': 'hashlib'},{'id': '79', 'type': 'identifier', 'children': [], 'value': 'sha256'},{'id': '80', 'type': 'argument_list', 'children': ['81']},{'id': '81', 'type': 'call', 'children': ['82', '85']},{'id': '82', 'type': 'attribute', 'children': ['83', '84']},{'id': '83', 'type': 'identifier', 'children': [], 'value': 'key_json'},{'id': '84', 'type': 'identifier', 'children': [], 'value': 'encode'},{'id': '85', 'type': 'argument_list', 'children': ['86']},{'id': '86', 'type': 'string', 'children': [], 'value': "'utf-8'"},{'id': '87', 'type': 'identifier', 'children': [], 'value': 'hexdigest'},{'id': '88', 'type': 'argument_list', 'children': []}
def _gen_cache_key_for_slice(url_dict, start_int, total_int, authn_subj_list): key_url_dict = copy.deepcopy(url_dict) key_url_dict['query'].pop('start', None) key_url_dict['query'].pop('count', None) key_json = d1_common.util.serialize_to_normalized_compact_json( { 'url_dict': key_url_dict, 'start': start_int, 'total': total_int, 'subject': authn_subj_list, } ) logging.debug('key_json={}'.format(key_json)) return hashlib.sha256(key_json.encode('utf-8')).hexdigest()
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'normalize'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'rp_pyxb'},{'id': '5', 'type': 'block', 'children': ['6', '25', '47', '53']},{'id': '6', 'type': 'function_definition', 'children': ['7', '8', '11']},{'id': '7', 'type': 'function_name', 'children': [], 'value': 'sort'},{'id': '8', 'type': 'parameters', 'children': ['9', '10']},{'id': '9', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'a'},{'id': '11', 'type': 'block', 'children': ['12']},{'id': '12', 'type': 'expression_statement', 'children': ['13']},{'id': '13', 'type': 'call', 'children': ['14', '19']},{'id': '14', 'type': 'attribute', 'children': ['15', '18']},{'id': '15', 'type': 'attribute', 'children': ['16', '17']},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'd1_common'},{'id': '17', 'type': 'identifier', 'children': [], 'value': 'xml'},{'id': '18', 'type': 'identifier', 'children': [], 'value': 'sort_value_list_pyxb'},{'id': '19', 'type': 'argument_list', 'children': ['20']},{'id': '20', 'type': 'call', 'children': ['21', '22']},{'id': '21', 'type': 'identifier', 'children': [], 'value': '_get_attr_or_list'},{'id': '22', 'type': 'argument_list', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'r'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'a'},{'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': 'rp_pyxb'},{'id': '29', 'type': 'identifier', 'children': [], 'value': 'preferredMemberNode'},{'id': '30', 'type': 'binary_operator', 'children': ['31', '39'], 'value': '-'},{'id': '31', 'type': 'call', 'children': ['32', '33']},{'id': '32', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '33', 'type': 'argument_list', 'children': ['34']},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': '_get_attr_or_list'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'rp_pyxb'},{'id': '38', 'type': 'string', 'children': [], 'value': "'pref'"},{'id': '39', 'type': 'call', 'children': ['40', '41']},{'id': '40', 'type': 'identifier', 'children': [], 'value': 'set'},{'id': '41', 'type': 'argument_list', 'children': ['42']},{'id': '42', 'type': 'call', 'children': ['43', '44']},{'id': '43', 'type': 'identifier', 'children': [], 'value': '_get_attr_or_list'},{'id': '44', 'type': 'argument_list', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'rp_pyxb'},{'id': '46', 'type': 'string', 'children': [], 'value': "'block'"},{'id': '47', 'type': 'expression_statement', 'children': ['48']},{'id': '48', 'type': 'call', 'children': ['49', '50']},{'id': '49', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '50', 'type': 'argument_list', 'children': ['51', '52']},{'id': '51', 'type': 'identifier', 'children': [], 'value': 'rp_pyxb'},{'id': '52', 'type': 'string', 'children': [], 'value': "'block'"},{'id': '53', 'type': 'expression_statement', 'children': ['54']},{'id': '54', 'type': 'call', 'children': ['55', '56']},{'id': '55', 'type': 'identifier', 'children': [], 'value': 'sort'},{'id': '56', 'type': 'argument_list', 'children': ['57', '58']},{'id': '57', 'type': 'identifier', 'children': [], 'value': 'rp_pyxb'},{'id': '58', 'type': 'string', 'children': [], 'value': "'pref'"}
def normalize(rp_pyxb): def sort(r, a): d1_common.xml.sort_value_list_pyxb(_get_attr_or_list(r, a)) rp_pyxb.preferredMemberNode = set(_get_attr_or_list(rp_pyxb, 'pref')) - set( _get_attr_or_list(rp_pyxb, 'block') ) sort(rp_pyxb, 'block') sort(rp_pyxb, 'pref')
{'id': '0', 'type': 'module', 'children': ['1']},{'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']},{'id': '2', 'type': 'function_name', 'children': [], 'value': 'normalize'},{'id': '3', 'type': 'parameters', 'children': ['4']},{'id': '4', 'type': 'identifier', 'children': [], 'value': 'body_part_tup'},{'id': '5', 'type': 'block', 'children': ['6']},{'id': '6', 'type': 'return_statement', 'children': ['7']},{'id': '7', 'type': 'call', 'children': ['8', '11']},{'id': '8', 'type': 'attribute', 'children': ['9', '10']},{'id': '9', 'type': 'string', 'children': [], 'value': "'\\n\\n'"},{'id': '10', 'type': 'identifier', 'children': [], 'value': 'join'},{'id': '11', 'type': 'argument_list', 'children': ['12']},{'id': '12', 'type': 'list_comprehension', 'children': ['13', '32']},{'id': '13', 'type': 'call', 'children': ['14', '17']},{'id': '14', 'type': 'attribute', 'children': ['15', '16']},{'id': '15', 'type': 'string', 'children': [], 'value': "'{}\\n\\n{}'"},{'id': '16', 'type': 'identifier', 'children': [], 'value': 'format'},{'id': '17', 'type': 'argument_list', 'children': ['18', '29']},{'id': '18', 'type': 'call', 'children': ['19', '20']},{'id': '19', 'type': 'identifier', 'children': [], 'value': 'str'},{'id': '20', 'type': 'argument_list', 'children': ['21', '26']},{'id': '21', 'type': 'subscript', 'children': ['22', '25']},{'id': '22', 'type': 'attribute', 'children': ['23', '24']},{'id': '23', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '24', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '25', 'type': 'string', 'children': [], 'value': "b'Content-Disposition'"},{'id': '26', 'type': 'attribute', 'children': ['27', '28']},{'id': '27', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '28', 'type': 'identifier', 'children': [], 'value': 'encoding'},{'id': '29', 'type': 'attribute', 'children': ['30', '31']},{'id': '30', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '31', 'type': 'identifier', 'children': [], 'value': 'text'},{'id': '32', 'type': 'for_in_clause', 'children': ['33', '34']},{'id': '33', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '34', 'type': 'call', 'children': ['35', '36']},{'id': '35', 'type': 'identifier', 'children': [], 'value': 'sorted'},{'id': '36', 'type': 'argument_list', 'children': ['37', '38']},{'id': '37', 'type': 'identifier', 'children': [], 'value': 'body_part_tup'},{'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']},{'id': '39', 'type': 'identifier', 'children': [], 'value': 'key'},{'id': '40', 'type': 'lambda', 'children': ['41', '43']},{'id': '41', 'type': 'lambda_parameters', 'children': ['42']},{'id': '42', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '43', 'type': 'subscript', 'children': ['44', '47']},{'id': '44', 'type': 'attribute', 'children': ['45', '46']},{'id': '45', 'type': 'identifier', 'children': [], 'value': 'p'},{'id': '46', 'type': 'identifier', 'children': [], 'value': 'headers'},{'id': '47', 'type': 'string', 'children': [], 'value': "b'Content-Disposition'"}
def normalize(body_part_tup,): return '\n\n'.join( [ '{}\n\n{}'.format( str(p.headers[b'Content-Disposition'], p.encoding), p.text ) for p in sorted( body_part_tup, key=lambda p: p.headers[b'Content-Disposition'] ) ] )