code: def _wrap_with_curdoc(
      doc: Document, f: Callable[..., Any]
  ) -> Callable[..., Any]:
      @wraps(f)
      def wrapper(*args: Any, **kwargs: Any) -> None:
          @wraps(f)
          def invoke() -> Any:
              return f(*args, **kwargs)
  
          return invoke_with_curdoc(doc, invoke)
  
      return wrapper
  
imports: from __future__ import annotations
  import logging
  import weakref
  from collections import defaultdict
  from functools import wraps
  from typing import TYPE_CHECKING, Any, Callable
  from ..core.enums import HoldPolicy, HoldPolicyType
  from ..events import _CONCRETE_EVENT_CLASSES, DocumentEvent, Event, ModelEvent
  from ..model import Model
  from ..models.callbacks import Callback
  from ..util.callback_manager import _check_callback
  from .events import DocumentPatchedEvent, ModelChangedEvent, RootAddedEvent, RootRemovedEvent, SessionCallbackAdded, SessionCallbackRemoved, TitleChangedEvent
  from .locking import UnlockedDocumentProxy
label_desc: Use image node_id 3 for calling a global function with example usage: _wrap_with_curdoc(doc, f) and returns: wrapper, invoke_with_curdoc, f