

def __init__(self, url_or_file=None, profile=None, profile_dir=None, ipython_dir=None, context=None, debug=False, exec_key=None, sshserver=None, sshkey=None, password=None, paramiko=None, timeout=10, **extra_args):
    if profile:
        super(Client, self).__init__(debug=debug, profile=profile)
    else:
        super(Client, self).__init__(debug=debug)
    if (context is None):
        context = zmq.Context.instance()
    self._context = context
    self._setup_profile_dir(self.profile, profile_dir, ipython_dir)
    if (self._cd is not None):
        if (url_or_file is None):
            url_or_file = pjoin(self._cd.security_dir, 'ipcontroller-client.json')
    assert (url_or_file is not None), "I can't find enough information to connect to a hub! Please specify at least one of url_or_file or profile."
    try:
        util.validate_url(url_or_file)
    except AssertionError:
        if (not os.path.exists(url_or_file)):
            if self._cd:
                url_or_file = os.path.join(self._cd.security_dir, url_or_file)
            assert os.path.exists(url_or_file), ('Not a valid connection file or url: %r' % url_or_file)
        with open(url_or_file) as f:
            cfg = json.loads(f.read())
    else:
        cfg = {
            'url': url_or_file,
        }
    if sshserver:
        cfg['ssh'] = sshserver
    if exec_key:
        cfg['exec_key'] = exec_key
    exec_key = cfg['exec_key']
    location = cfg.setdefault('location', None)
    cfg['url'] = util.disambiguate_url(cfg['url'], location)
    url = cfg['url']
    (proto, addr, port) = util.split_url(url)
    if ((location is not None) and (addr == '127.0.0.1')):
        if ((location not in LOCAL_IPS) and (not sshserver)):
            sshserver = cfg['ssh']
        if ((location not in LOCAL_IPS) and (not sshserver)):
            warnings.warn(("\n            Controller appears to be listening on localhost, but not on this machine.\n            If this is true, you should specify Client(...,sshserver='you@%s')\n            or instruct your controller to listen on an external IP." % location), RuntimeWarning)
    elif (not sshserver):
        sshserver = cfg['ssh']
    self._config = cfg
    self._ssh = bool((sshserver or sshkey or password))
    if (self._ssh and (sshserver is None)):
        sshserver = url.split('://')[1].split(':')[0]
    if (self._ssh and (password is None)):
        if tunnel.try_passwordless_ssh(sshserver, sshkey, paramiko):
            password = False
        else:
            password = getpass(('SSH Password for %s: ' % sshserver))
    ssh_kwargs = dict(keyfile=sshkey, password=password, paramiko=paramiko)
    if (exec_key is not None):
        if os.path.isfile(exec_key):
            extra_args['keyfile'] = exec_key
        else:
            exec_key = util.asbytes(exec_key)
            extra_args['key'] = exec_key
    self.session = Session(**extra_args)
    self._query_socket = self._context.socket(zmq.XREQ)
    self._query_socket.setsockopt(zmq.IDENTITY, util.asbytes(self.session.session))
    if self._ssh:
        tunnel.tunnel_connection(self._query_socket, url, sshserver, **ssh_kwargs)
    else:
        self._query_socket.connect(url)
    self.session.debug = self.debug
    self._notification_handlers = {
        'registration_notification': self._register_engine,
        'unregistration_notification': self._unregister_engine,
        'shutdown_notification': (lambda msg: self.close()),
    }
    self._queue_handlers = {
        'execute_reply': self._handle_execute_reply,
        'apply_reply': self._handle_apply_reply,
    }
    self._connect(sshserver, ssh_kwargs, timeout)

dataset/ETHPy150Open ipython/ipython-py3k/IPython/parallel/client/client.py Client.__init__/original