code: def dependency_state(widgets, drop_defaults=True):
      """Get the state of all widgets specified, and their dependencies.
  
      This uses a simple dependency finder, including:
       - any widget directly referenced in the state of an included widget
       - any widget in a list/tuple attribute in the state of an included widget
       - any widget in a dict attribute in the state of an included widget
       - any jslink/jsdlink between two included widgets
      What this alogrithm does not do:
       - Find widget references in nested list/dict structures
       - Find widget references in other types of attributes
  
      Note that this searches the state of the widgets for references, so if
      a widget reference is not included in the serialized state, it won't
      be considered as a dependency.
  
      Parameters
      ----------
      widgets: single widget or list of widgets.
         This function will return the state of every widget mentioned
         and of all their dependencies.
      drop_defaults: boolean
          Whether to drop default values from the widget states.
  
      Returns
      -------
      A dictionary with the state of the widgets and any widget they
      depend on.
      """
      # collect the state of all relevant widgets
      if widgets is None:
          # Get state of all widgets, no smart resolution needed.
          state = Widget.get_manager_state(
              drop_defaults=drop_defaults, widgets=None
          )["state"]
      else:
          try:
              widgets[0]
          except (IndexError, TypeError):
              widgets = [widgets]
          state = {}
          for widget in widgets:
              _get_recursive_state(widget, state, drop_defaults)
          # Add any links between included widgets:
          add_resolved_links(state, drop_defaults)
      return state
  
file_path: catboost/contrib/python/ipywidgets/py2/ipywidgets/embed.py
imports: import json
  import re
  from .widgets import Widget, DOMWidget
  from .widgets.widget_link import Link
  from .widgets.docutils import doc_subst
  from ._version import __html_manager_version__
label_desc: Use image node_id 4 for calling a global function with example usage: dependency_state(widgets, drop_defaults) and returns: state