<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def connect( host="localhost", port=1113, discovery_host=None, discovery_port=2113, username=None, password=None, loop=None, name=None, selector=select_random, ) -> Client: """ Create a new client. Examples: Since the Client is an async context manager, we can use it in a with block for automatic connect/disconnect semantics. Or we can call connect at a more convenient moment For cluster discovery cases, we can provide a discovery host and port. The host may be an IP or DNS entry. If you provide a DNS entry, discovery will choose randomly from the registered IP addresses for the hostname. The discovery host returns gossip data about the cluster. We use the gossip to select a node at random from the avaialble cluster members. If you're using :meth:`persistent subscriptions <photonpump.connection.Client.create_subscription>` you will always want to connect to the master node of the cluster. The selector parameter is a function that chooses an available node from the gossip result. To select the master node, use the :func:`photonpump.discovery.prefer_master` function. This function will return the master node if there is a live master, and a random replica otherwise. All requests to the server can be made with the require_master flag which will raise an error if the current node is not a master. Conversely, you might want to avoid connecting to the master node for reasons of scalability. For this you can use the :func:`photonpump.discovery.prefer_replica` function. For some operations, you may need to authenticate your requests by providing a username and password to the client. Ordinarily you will create a single Client per application, but for advanced scenarios you might want multiple connections. In this situation, you can name each connection in order to get better logging. Args: host: The IP or DNS entry to connect with, defaults to 'localhost'. port: The port to connect with, defaults to 1113. discovery_host: The IP or DNS entry to use for cluster discovery. discovery_port: The port to use for cluster discovery, defaults to 2113. username: The username to use when communicating with eventstore. password: The password to use when communicating with eventstore. loop:An Asyncio event loop. selector: An optional function that selects one element from a list of :class:`photonpump.disovery.DiscoveredNode` elements. """

    discovery = get_discoverer(host, port, discovery_host, discovery_port, selector)
    dispatcher = MessageDispatcher(name=name, loop=loop)
    connector = Connector(discovery, dispatcher, name=name)

    credential = msg.Credential(username, password) if username and password else None

    return Client(connector, dispatcher, credential=credential)