code: def register_handler(self, name, metadata, callback):
      
      assert name not in self._handlers, 'duplicate handler name: {}'.format(name)
      assert (
        isinstance(metadata, dict) and 'fields' in metadata and 'expression' in metadata
      ), 'invalid handler metadata!'
      self._handlers[name] = Watchman.EventHandler(name=name, metadata=metadata, callback=callback)
docs: Register subscriptions and their event handlers.
  
      :param str name:      the subscription name as used by watchman
      :param dict metadata: a dictionary of metadata to be serialized and passed to the watchman
                            subscribe command. this should include the match expression as well
                            as any required callback fields.
      :param func callback: the callback to execute on each matching filesystem event