def _filter_namespaces_by_route_whitelist(self):
assert self._routes is not None, "<STR_LIT>"<EOL>assert '<STR_LIT>' in self._routes<EOL>assert '<STR_LIT>' in self._routes<EOL>route_whitelist = {}<EOL>for namespace_name, route_reprs in self._routes['<STR_LIT>'].items():<EOL><INDENT>new_route_reprs = []<EOL>if route_reprs == ['<STR_LIT:*>']:<EOL><INDENT>namespace = self.api.namespaces[namespace_name]<EOL>new_route_reprs = [route.name_with_version() for route in namespace.routes]<EOL><DEDENT>else:<EOL><INDENT>for route_repr in route_reprs:<EOL><INDENT>route_name, version = parse_route_name_and_version(route_repr)<EOL>if version > <NUM_LIT:1>:<EOL><INDENT>new_route_reprs.append('<STR_LIT>'.format(route_name, version))<EOL><DEDENT>else:<EOL><INDENT>new_route_reprs.append(route_name)<EOL><DEDENT><DEDENT><DEDENT>route_whitelist[namespace_name] = new_route_reprs<EOL><DEDENT>route_data_types = []<EOL>for namespace_name, route_reprs in route_whitelist.items():<EOL><INDENT>if namespace_name not in self.api.namespaces:<EOL><INDENT>raise AssertionError('<STR_LIT>' % namespace_name)<EOL><DEDENT>namespace = self.api.namespaces[namespace_name]<EOL>if namespace.doc is not None:<EOL><INDENT>route_data_types.extend(<EOL>parse_data_types_from_doc_ref(self.api, namespace.doc, namespace_name))<EOL><DEDENT>assert '<STR_LIT:*>' not in route_reprs<EOL>for routes_repr in route_reprs:<EOL><INDENT>route_name, version = parse_route_name_and_version(routes_repr)<EOL>if route_name not in namespace.routes_by_name orversion not in namespace.routes_by_name[route_name].at_version:<EOL><INDENT>raise AssertionError('<STR_LIT>' %<EOL>(route_name, version))<EOL><DEDENT>route = namespace.routes_by_name[route_name].at_version[version]<EOL>route_data_types.extend(namespace.get_route_io_data_types_for_route(route))<EOL>if route.doc is not None:<EOL><INDENT>route_data_types.extend(<EOL>parse_data_types_from_doc_ref(self.api, route.doc, namespace_name))<EOL><DEDENT><DEDENT><DEDENT>for namespace_name, datatype_names in self._routes['<STR_LIT>'].items():<EOL><INDENT>if namespace_name not in self.api.namespaces:<EOL><INDENT>raise AssertionError('<STR_LIT>' % namespace_name)<EOL><DEDENT>namespace = self.api.namespaces[namespace_name]<EOL>if namespace.doc is not None:<EOL><INDENT>route_data_types.extend(<EOL>parse_data_types_from_doc_ref(self.api, namespace.doc, namespace_name))<EOL><DEDENT>for datatype_name in datatype_names:<EOL><INDENT>if datatype_name not in self.api.namespaces[namespace_name].data_type_by_name:<EOL><INDENT>raise AssertionError('<STR_LIT>' % datatype_name)<EOL><DEDENT>data_type = self.api.namespaces[namespace_name].data_type_by_name[datatype_name]<EOL>route_data_types.append(data_type)<EOL><DEDENT><DEDENT>output_types_by_ns, output_routes_by_ns = self._find_dependencies(route_data_types)<EOL>for namespace in self.api.namespaces.values():<EOL><INDENT>data_types = list(set(output_types_by_ns[namespace.name]))  <EOL>namespace.data_types = data_types<EOL>namespace.data_type_by_name = {d.name: d for d in data_types}<EOL>output_route_reprs = [output_route.name_with_version()<EOL>for output_route in output_routes_by_ns[namespace.name]]<EOL>if namespace.name in route_whitelist:<EOL><INDENT>whitelisted_route_reprs = route_whitelist[namespace.name]<EOL>route_reprs = list(set(whitelisted_route_reprs + output_route_reprs))<EOL><DEDENT>else:<EOL><INDENT>route_reprs = output_route_reprs<EOL><DEDENT>routes = []<EOL>for route_repr in route_reprs:<EOL><INDENT>route_name, version = parse_route_name_and_version(route_repr)<EOL>route = namespace.routes_by_name[route_name].at_version[version]<EOL>routes.append(route)<EOL><DEDENT>namespace.routes = []<EOL>namespace.route_by_name = {}<EOL>namespace.routes_by_name = {}<EOL>for route in routes:<EOL><INDENT>namespace.add_route(route)<EOL><DEDENT><DEDENT>
Given a parsed API in IR form, filter the user-defined datatypes
so that they include only the route datatypes and their direct dependencies.