def patch_base_handler(BaseHandler, log=None):
    """Patch HubAuthenticated into a base handler class

    so anything inheriting from BaseHandler uses Hub authentication.
    This works *even after* subclasses have imported and inherited from BaseHandler.

    .. versionadded: 1.5
        Made available as an importable utility
    """
    if log is None:
        log = logging.getLogger()

    if HubAuthenticatedHandler not in BaseHandler.__bases__:
        new_bases = (HubAuthenticatedHandler,) + BaseHandler.__bases__
        log.info(
            "Patching auth into {mod}.{name}({old_bases}) -> {name}({new_bases})".format(
                mod=BaseHandler.__module__,
                name=BaseHandler.__name__,
                old_bases=', '.join(
                    _nice_cls_repr(cls) for cls in BaseHandler.__bases__
                ),
                new_bases=', '.join(_nice_cls_repr(cls) for cls in new_bases),
            )
        )
        BaseHandler.__bases__ = new_bases
        # We've now inserted our class as a parent of BaseHandler,
        # but we also need to ensure BaseHandler *itself* doesn't
        # override the public tornado API methods we have inserted.
        # If they are defined in BaseHandler, explicitly replace them with our methods.
        for name in ("get_current_user", "get_login_url", "check_xsrf_cookie"):
            if name in BaseHandler.__dict__:
                log.debug(
                    f"Overriding {BaseHandler}.{name} with HubAuthenticatedHandler.{name}"
                )
                method = getattr(HubAuthenticatedHandler, name)
                setattr(BaseHandler, name, method)
    return BaseHandler
Patch HubAuthenticated into a base handler class

so anything inheriting from BaseHandler uses Hub authentication.
This works *even after* subclasses have imported and inherited from BaseHandler.

.. versionadded: 1.5
Made available as an importable utility
jupyterhub/singleuser/mixins.py