code: def Connect(self, Username, WaitConnected=False):
          
          if WaitConnected:
              self._Connect_Event = threading.Event()
              self._Connect_Stream = [None]
              self._Connect_Username = Username
              self._Connect_ApplicationStreams(self, self.Streams)
              self._Owner.RegisterEventHandler('ApplicationStreams', self._Connect_ApplicationStreams)
              self._Alter('CONNECT', Username)
              self._Connect_Event.wait()
              self._Owner.UnregisterEventHandler('ApplicationStreams', self._Connect_ApplicationStreams)
              try:
                  return self._Connect_Stream[0]
              finally:
                  del self._Connect_Stream, self._Connect_Event, self._Connect_Username
          else:
              self._Alter('CONNECT', Username)
docs: Connects application to user.
  
          :Parameters:
            Username : str
              Name of the user to connect to.
            WaitConnected : bool
              If True, causes the method to wait until the connection is established.
  
          :return: If ``WaitConnected`` is True, returns the stream which can be used to send the
                   data. Otherwise returns None.
          :rtype: `ApplicationStream` or None