<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def for_(cls, operation, ns, qs=None, type=None, allow_templates=False, **kwargs):
 """ Create a link to an operation on a resource object. Supports link templating if enabled by making a best guess as to the URI template construction. See also [RFC 6570]( https://tools.ietf.org/html/rfc6570). :param operation: the operation :param ns: the namespace :param qs: an optional query string (e.g. for paging) :param type: an optional link type :param allow_templates: whether generated links are allowed to contain templates :param kwargs: optional endpoint expansion arguments (e.g. for URI parameters) :raises BuildError: if link templating is needed and disallowed """

        assert isinstance(ns, Namespace)
        try:
            href, templated = ns.href_for(operation, qs=qs, **kwargs), False
        except BuildError as error:
            if not allow_templates:
                raise
            uri_templates = {
                argument: "{{{}}}".format(argument)
                for argument in error.suggested.arguments
            }
            kwargs.update(uri_templates)
            href, templated = ns.href_for(operation, qs=qs, **kwargs), True

        return cls(
            href=href,
            type=type,
            templated=templated,
        )