code: def on(self, event, handler=None):
          
          if event not in self.event_names:
              raise ValueError('Invalid event')
  
          def set_handler(handler):
              self.handlers[event] = handler
              return handler
  
          if handler is None:
              return set_handler
          set_handler(handler)
docs: Register an event handler.
  
          :param event: The event name. Can be ``'connect'``, ``'message'`` or
                        ``'disconnect'``.
          :param handler: The function that should be invoked to handle the
                          event. When this parameter is not given, the method
                          acts as a decorator for the handler function.
  
          Example usage::
  
              # as a decorator:
              @eio.on('connect')
              def connect_handler():
                  print('Connection request')
  
              # as a method:
              def message_handler(msg):
                  print('Received message: ', msg)
                  eio.send('response')
              eio.on('message', message_handler)