def _generate_init(class_, class_manager):

    # TODO: we should use the ClassManager's notion of the
    # original '__init__' method, once ClassManager is fixed
    # to always reference that.
    original__init__ = class_.__init__
    assert original__init__

    # Go through some effort here and don't change the user's __init__
    # calling signature, including the unlikely case that it has
    # a return value.
    # FIXME: need to juggle local names to avoid constructor argument
    # clashes.
    func_body = """\
def __init__(%(apply_pos)s):
    new_state = class_manager._new_state_if_none(%(self_arg)s)
    if new_state:
        return new_state._initialize_instance(%(apply_kw)s)
    else:
        return original__init__(%(apply_kw)s)
"""
    func_vars = util.format_argspec_init(original__init__, grouped=False)
    func_text = func_body % func_vars

    if util.py2k:
        func = getattr(original__init__, 'im_func', original__init__)
        func_defaults = getattr(func, 'func_defaults', None)
    else:
        func_defaults = getattr(original__init__, '__defaults__', None)
        func_kw_defaults = getattr(original__init__, '__kwdefaults__', None)

    env = locals().copy()
    exec(func_text, env)
    __init__ = env['__init__']
    __init__.__doc__ = original__init__.__doc__

    if func_defaults:
        __init__.__defaults__ = func_defaults
    if not util.py2k and func_kw_defaults:
        __init__.__kwdefaults__ = func_kw_defaults

    return __init__
Validates given ip for use as rpc host bind address.
dataset/ETHPy150Open RoseOu/flasky/venv/lib/python2.7/site-packages/sqlalchemy/orm/instrumentation.py/_generate_init--crossover with--dataset/ETHPy150Open osrg/ryu/ryu/services/protocols/bgp/application.py/RyuBGPSpeaker.validate_rpc_ip