def monkeypatch_method(cls):
    """A function decorator to monkey-patch a method of the same name on the
    given class.
    """

    def wrapper(func):
        orig = getattr(cls, func.__name__, None)
        if orig and not hasattr(orig, '_orig'):  # Already patched
            setattr(func, '_orig', orig)
            setattr(cls, func.__name__, func)
        return func

    return wrapper