(cls)
Generate a _compiler_dispatch() external traversal on classes with a
    __visit_name__ attribute.
Generate a _compiler_dispatch() external traversal on classes with a
    __visit_name__ attribute.
Generate a _compiler_dispatch () external traversal on classes with a __visit_name__ attribute .
def _generate_compiler_dispatch(cls):
    """Generate a _compiler_dispatch() external traversal on classes with a
    __visit_name__ attribute.

    """
    visit_name = cls.__visit_name__

    if not isinstance(visit_name, util.compat.string_types):
        raise exc.InvalidRequestError(
            "__visit_name__ on class %s must be a string at the class level"
            % cls.__name__
        )

    code = (
        "def _compiler_dispatch(self, visitor, **kw):\n"
        "    try:\n"
        "        meth = visitor.visit_%(name)s\n"
        "    except AttributeError as err:\n"
        "        util.raise_(\n"
        "            exc.UnsupportedCompilationError(visitor, cls), \n"
        "            replace_context=err)\n"
        "    else:\n"
        "        return meth(self, **kw)\n"
    ) % {"name": visit_name}

    _compiler_dispatch = langhelpers._exec_code_in_env(
        code, {"exc": exc, "cls": cls, "util": util}, "_compiler_dispatch"
    )

    _compiler_dispatch.__doc__ = """Look for an attribute named "visit_"
        + self.__visit_name__ on the visitor, and call it with the same
        kw params.
        """
    cls._compiler_dispatch = _compiler_dispatch
def _generate_compiler_dispatch ( cls ) : visit_name = cls . __visit_name__ if not isinstance ( visit_name , util . compat . string_types ) : raise exc . InvalidRequestError ( "__visit_name__ on class %s must be a string at the class level" % cls . __name__ ) code = ( "def _compiler_dispatch(self, visitor, **kw):\n" "    try:\n" "        meth = visitor.visit_%(name)s\n" "    except AttributeError as err:\n" "        util.raise_(\n" "            exc.UnsupportedCompilationError(visitor, cls), \n" "            replace_context=err)\n" "    else:\n" "        return meth(self, **kw)\n" ) % { "name" : visit_name } _compiler_dispatch = langhelpers . _exec_code_in_env ( code , { "exc" : exc , "cls" : cls , "util" : util } , "_compiler_dispatch" ) _compiler_dispatch . __doc__ = """Look for an attribute named "visit_"
        + self.__visit_name__ on the visitor, and call it with the same
        kw params.
        """ cls . _compiler_dispatch = _compiler_dispatch