''

def _with_self_as_curdoc(self, f):

    from bokeh.io import set_curdoc, curdoc
    old_doc = curdoc()
    try:
        if getattr(f, 'nolock', False):
            set_curdoc(_UnlockedDocumentProxy(self))
        else:
            set_curdoc(self)
        return f()
    finally:
        set_curdoc(old_doc)
