code: def get_state(self, key=None, drop_defaults=False):
          
          if key is None:
              keys = self.keys
          elif isinstance(key, string_types):
              keys = [key]
          elif isinstance(key, collections.Iterable):
              keys = key
          else:
              raise ValueError("key must be a string, an iterable of keys, or None")
          state = {}
          traits = self.traits()
          for k in keys:
              to_json = self.trait_metadata(k, 'to_json', self._trait_to_json)
              value = to_json(getattr(self, k), self)
              if not PY3 and isinstance(traits[k], Bytes) and isinstance(value, bytes):
                  value = memoryview(value)
              if not drop_defaults or not self._compare(value, traits[k].default_value):
                  state[k] = value
          return state
docs: Gets the widget state, or a piece of it.
  
          Parameters
          ----------
          key : unicode or iterable (optional)
              A single property's name or iterable of property names to get.
  
          Returns
          -------
          state : dict of states
          metadata : dict
              metadata for each field: {key: metadata}