'Augment `self.routes` with any dynamically generated routes.
Returns a list of the Route namedtuple.'

def get_routes(self, viewset):

    known_actions = list(flatten([route.mapping.values() for route in self.routes if isinstance(route, Route)]))
    detail_routes = []
    list_routes = []
    for methodname in dir(viewset):
        attr = getattr(viewset, methodname)
        httpmethods = getattr(attr, u'bind_to_methods', None)
        detail = getattr(attr, u'detail', True)
        if httpmethods:
            if (methodname in known_actions):
                raise ImproperlyConfigured((u'Cannot    use    @detail_route    or    @list_route    decorators    on    method    "%s"    as    it    is    an    existing    route' % methodname))
            httpmethods = [method.lower() for method in httpmethods]
            if detail:
                detail_routes.append((httpmethods, methodname))
            else:
                list_routes.append((httpmethods, methodname))
    def _get_dynamic_routes(route, dynamic_routes):
        ret = []
        for (httpmethods, methodname) in dynamic_routes:
            method_kwargs = getattr(viewset, methodname).kwargs
            initkwargs = route.initkwargs.copy()
            initkwargs.update(method_kwargs)
            url_path = (initkwargs.pop(u'url_path', None) or methodname)
            url_path = escape_curly_brackets(url_path)
            url_name = (initkwargs.pop(u'url_name', None) or url_path)
            ret.append(Route(url=replace_methodname(route.url, url_path), mapping={httpmethod: methodname for httpmethod in httpmethods}, name=replace_methodname(route.name, url_name), initkwargs=initkwargs))
        return ret
    ret = []
    for route in self.routes:
        if isinstance(route, DynamicDetailRoute):
            ret += _get_dynamic_routes(route, detail_routes)
        elif isinstance(route, DynamicListRoute):
            ret += _get_dynamic_routes(route, list_routes)
        else:
            ret.append(route)
    return ret
