Connect and logins to an Apple TV.
10190
def connect_to_apple_tv(details, loop, protocol=None, session=None):
    """"""
    service = _get_service_used_to_connect(details, protocol)

    # If no session is given, create a default one
    if session is None:
        session = ClientSession(loop=loop)

    # AirPlay service is the same for both DMAP and MRP
    airplay = _setup_airplay(loop, session, details)

    # Create correct implementation depending on protocol
    if service.protocol == PROTOCOL_DMAP:
        return DmapAppleTV(loop, session, details, airplay)

    return MrpAppleTV(loop, session, details, airplay)
1092139
def connect(self, addr):
        """"""
        if _debug: DeviceToDeviceClientService._debug("connect %r", addr)

        # make a connection
        conn = ConnectionState(addr)
        self.multiplexer.connections[addr] = conn

        # associate with this service, but it is not connected until the ack comes back
        conn.service = self

        # keep a list of pending NPDU objects until the ack comes back
        conn.pendingNPDU = []

        # build a service request
        request = ServiceRequest(DEVICE_TO_DEVICE_SERVICE_ID)
        request.pduDestination = addr

        # send it
        self.service_request(request)

        # return the connection object
        return conn
734208
def connect(self):
        """"""
        if time.time() < self._login_cooldown:
            raise FailedToConnect("login on cooldown")

        resp = yield from self.session.post("https://connect.ubi.com/ubiservices/v2/profiles/sessions", headers = {
            "Content-Type": "application/json",
            "Ubi-AppId": self.appid,
            "Authorization": "Basic " + self.token
        }, data=json.dumps({"rememberMe": True}))

        data = yield from resp.json()

        if "ticket" in data:
            self.key = data.get("ticket")
            self.sessionid = data.get("sessionId")
            self.uncertain_spaceid = data.get("spaceId")
        else:
            raise FailedToConnect
1326702
def connect(self, opt):
        """"""
        if not self._kwargs['verify']:
            LOG.warning('Skipping SSL Validation!')

        self.version = self.server_version()
        self.token = self.init_token()
        my_token = self.lookup_token()
        if not my_token or 'data' not in my_token:
            raise aomi.exceptions.AomiCredentials('initial token')

        display_name = my_token['data']['display_name']
        vsn_string = ""
        if self.version:
            vsn_string = ", v%s" % self.version
        else:
            LOG.warning("Unable to deterine Vault version. Not all "
                        "functionality is supported")

        LOG.info("Connected to %s as %s%s",
                 self._url,
                 display_name,
                 vsn_string)

        if opt.reuse_token:
            LOG.debug("Not creating operational token")
            self.initial_token = self.token
            self.operational_token = self.token
        else:
            self.initial_token = self.token
            self.operational_token = self.op_token(display_name, opt)
            if not self.is_authenticated():
                raise aomi.exceptions.AomiCredentials('operational token')

            self.token = self.operational_token

        return self
365550
def connect(self, clientId=0, host="localhost", port=4001):
        
        self.clientId = clientId
        self.host = host
        self.port = port
        self.ibConn = Connection.create(
            host=self.host,
            port=int(self.port),
            clientId=self.clientId
        )

        # Assign server messages handling function.
        self.ibConn.registerAll(self.handleServerEvents)

        # connect
        self.log.info("[CONNECTING TO IB]")
        self.ibConn.connect()

        # get server time
        self.getServerTime()

        # subscribe to position and account changes
        self.subscribeAccount = False
        self.requestAccountUpdates(subscribe=True)

        self.subscribePositions = False
        self.requestPositionUpdates(subscribe=True)

        # load working orders
        self.requestOpenOrders()

        # force refresh of orderId upon connect
        self.handleNextValidId(self.orderId)

        self._disconnected_by_user = False
        time.sleep(1)
706532
def login(username, password, optional = nil)
      set_ssh_options(username, password, port=22, conn_timeout=nil)
      @volume = VolumeManager.new(@http, @ssh, @app_type)
      @http.authenticate(username, password, optional)
    end
750458
async def turn_on(self):
        """"""
        _LOGGER.debug("turn_on while %s", self._state)
        if self._state in [State.STANDBY, State.OFF, State.UNKNOWN]:
            await self.send_cmd('Power')
            self._state = State.PLAYING_LIVE_TV
        return self._state
1208059
def connect(self, obj, params):
        """"""

        connect_params = WLAN_CONNECTION_PARAMETERS()
        connect_params.wlanConnectionMode = 0  # Profile
        connect_params.dot11BssType = 1  # infra
        profile_name = create_unicode_buffer(params.ssid)

        connect_params.strProfile = profile_name.value
        ret = self._wlan_connect(
            self._handle, obj['guid'], byref(connect_params))
        self._logger.debug('connect result: %d', ret)
28975
async def scan(self):
        """"""
        atvs = await pyatv.scan_for_apple_tvs(
            self.loop, timeout=self.args.scan_timeout, only_usable=False)
        _print_found_apple_tvs(atvs)

        return 0
632668
async def scan_for_apple_tvs(loop, timeout=5, abort_on_found=False,
                             device_ip=None, only_usable=True,
                             protocol=None):
    """"""
    semaphore = asyncio.Semaphore(value=0, loop=loop)
    listener = _ServiceListener(
        loop, abort_on_found, device_ip, protocol, semaphore)
    zeroconf = Zeroconf()
    try:
        ServiceBrowser(zeroconf, HOMESHARING_SERVICE, listener)
        ServiceBrowser(zeroconf, DEVICE_SERVICE, listener)
        ServiceBrowser(zeroconf, MEDIAREMOTE_SERVICE, listener)
        ServiceBrowser(zeroconf, AIRPLAY_SERVICE, listener)
        _LOGGER.debug('Discovering devices for %d seconds', timeout)
        await asyncio.wait_for(semaphore.acquire(), timeout, loop=loop)
    except concurrent.futures.TimeoutError:
        pass  # Will happen when timeout occurs (totally normal)
    finally:
        zeroconf.close()

    def _should_include(atv):
        if not only_usable:
            return True

        return atv.is_usable()

    return list(filter(_should_include, listener.found_devices.values()))
93400
async def play_url(self, url, position=0):
        """"""
        headers = {'User-Agent': 'MediaControl/1.0',
                   'Content-Type': 'application/x-apple-binary-plist'}
        body = {'Content-Location': url, 'Start-Position': position}

        address = self._url(self.port, 'play')
        _LOGGER.debug('AirPlay %s to %s', url, address)

        resp = None
        try:
            # pylint: disable=no-member
            resp = await self.session.post(
                address, headers=headers,
                data=plistlib.dumps(body, fmt=plistlib.FMT_BINARY),
                timeout=TIMEOUT)
            await self._wait_for_media_to_end()
        finally:
            if resp is not None:
                resp.close()
1366653
def connect_login(self):
        
        self.client.connect(self.options['server'], self.options['port'], self.options['username'],
                            self.options['password'])
        self.comm_chan = self.client.invoke_shell()
        time.sleep(1)  # Let the server take some time to get ready.
        while not self.comm_chan.recv_ready():
            time.sleep(0.5)
        login_response = self.comm_chan.recv(2048)
        if not login_response.endswith('$ '):
            raise AuthenticationFailed
        return login_response
636990
function (username, password, callback) {

    var request;
    var promise;

    // Preemptively validate username and password
    if (!username) {
      throw new Error('Invalid credentials. Missing username.');
    }

    if (!password) {
      throw new Error('Invalid credentials. Missing password.');
    }

    // Execute the API request for authentication
    request = this.request({
      method: 'post',
      url: 'users/authenticate',
      form: {
        deviceToken: Vineapple.DEVICE_TOKEN || createDeviceToken([
          Vineapple.DEVICE_TOKEN_SEED,
          username,
          password
        ].join(':')),
        username: username,
        password: password
      }
    });

    promise = request.then(this.authorize.bind(this));

    if (callback) {
      promise.then(callback.bind(null, null)).fail(callback);
    }

    return promise;
  }
1018050
def connect(self):
        """"""
        self.socket = socket.create_connection(self.address, self.timeout)
239071
def connect(self, obj, network):
        """"""

        network_summary = self._send_cmd_to_wpas(
            obj['name'],
            'LIST_NETWORKS',
            True)
        network_summary = network_summary[:-1].split('\n')
        if len(network_summary) == 1:
            return networks

        for l in network_summary[1:]:
            values = l.split('\t')
            if values[1] == network.ssid:
                network_summary = self._send_cmd_to_wpas(
                    obj['name'],
                    'SELECT_NETWORK {}'.format(values[0]),
                    True)
940720
def main(options):
    """"""
        
    client = Client(server=options.server, username=options.username, password=options.password)
    print('Successfully connected to %s' % client.server)
    print(client.si.CurrentTime())
    
    client.logout()
1134506
def signedOn(self):
        """"""
        log.info("Signed on as %s.", self.nickname)
        if not self.password:
            # We aren't wating for auth, join all the channels
            self.joinChannels()
        else:
            self.msg("NickServ", "IDENTIFY %s" % self.password)