code: def from_dsn(cls, dsn, **kwargs):
          r
          init_args = _parse_dsn(dsn)
          host, port = init_args.pop('hosts')[0]
          init_args['host'] = host
          init_args['port'] = port
          init_args.update(kwargs)
  
          return cls(**init_args)
docs: r"""Generate an instance of InfluxDBClient from given data source name.
  
          Return an instance of :class:`~.InfluxDBClient` from the provided
          data source name. Supported schemes are "influxdb", "https+influxdb"
          and "udp+influxdb". Parameters for the :class:`~.InfluxDBClient`
          constructor may also be passed to this method.
  
          :param dsn: data source name
          :type dsn: string
          :param kwargs: additional parameters for `InfluxDBClient`
          :type kwargs: dict
          :raises ValueError: if the provided DSN has any unexpected values
  
          :Example:
  
          ::
  
              >> cli = InfluxDBClient.from_dsn('influxdb://username:password@\
              localhost:8086/databasename', timeout=5)
              >> type(cli)
              <class 'influxdb.client.InfluxDBClient'>
              >> cli = InfluxDBClient.from_dsn('udp+influxdb://username:pass@\
              localhost:8086/databasename', timeout=5, udp_port=159)
              >> print('{0._baseurl} - {0.use_udp} {0.udp_port}'.format(cli))
              http://localhost:8086 - True 159
  
          .. note:: parameters provided in `**kwargs` may override dsn parameters
          .. note:: when using "udp+influxdb" the specified port (if any) will
              be used for the TCP connection; specify the UDP port with the
              additional `udp_port` parameter (cf. examples).