コード例 #1
0
ファイル: wrappers.py プロジェクト: maffoo/pylabrad
def getConnection(host=C.MANAGER_HOST, port=C.MANAGER_PORT, name="Python Client", password=None):
    """Connect to LabRAD and return a deferred that fires the protocol object."""
    p = yield protocol.factory.connectTCP(host, port, C.TIMEOUT)
    if password is None:
        password = getPassword()
    yield p.loginClient(password, name)
    returnValue(p)
コード例 #2
0
ファイル: protocol.py プロジェクト: jdech1/pylabrad
    def authenticate(self, password):
        """Authenticate to the manager using the given password."""
        # send login packet
        resp = yield self.sendRequest(C.MANAGER_ID, [])
        challenge = resp[0][1] # get password challenge

        if password is None:
            password = getPassword()

        # send password response
        m = hashlib.md5()
        m.update(challenge)
        m.update(password)
        try:
            resp = yield self.sendRequest(C.MANAGER_ID, [(0L, m.digest())])
        except Exception:
            raise errors.LoginFailedError('Incorrect password.')
        self.password = C.PASSWORD = password # save password, since it worked
        self.loginMessage = resp[0][1] # get welcome message
コード例 #3
0
ファイル: backend.py プロジェクト: maffoo/pylabrad
 def login(self, password, *ident):
     # send login packet
     resp = self.sendRequest(C.MANAGER_ID, []).wait()
     challenge = resp[0][1] # get password challenge
 
     # send password response
     if password is None:
         password = getPassword()
     m = hashlib.md5()
     m.update(challenge)
     m.update(password)
     try:
         resp = self.sendRequest(C.MANAGER_ID, [(0L, m.digest())]).wait()
     except Exception:
         raise LoginFailedError('Incorrect password.')
     self.loginMessage = resp[0][1] # get welcome message
 
     # send identification
     try:
         resp = self.sendRequest(C.MANAGER_ID, [(0L, (1L,) + ident)]).wait()
     except Exception:
         raise LoginFailedError('Bad identification.')
     return resp[0][1] # get assigned ID
コード例 #4
0
ファイル: wrappers.py プロジェクト: Lambdauv/pylabrad
                            "accept this cert; [R]eject) ".format(host))
                    if ans.lower() in ['o', 's', 'r']:
                        break
                    else:
                        print 'Invalid input:', ans
                if ans.lower() == 'r':
                    raise
                p = yield connect()
                yield start_tls(p, cert)
                yield ping(p)
                if ans.lower() == 's':
                    # save now that we know TLS succeeded,
                    # including hostname verification.
                    crypto.save_cert(host, cert)
    if password is None:
        password = getPassword()
    yield p.loginClient(password, name)
    returnValue(p)

@inlineCallbacks
def connectAsync(host=C.MANAGER_HOST, port=None, name="Python Client",
                 password=None, tls=C.MANAGER_TLS):
    """Connect to LabRAD and return a deferred that fires the client object."""
    p = yield getConnection(host, port, name, password, tls=tls)
    cxn = IClientAsync(p)
    yield cxn._init()
    cxn.onDisconnect = p.onDisconnect
    returnValue(cxn)

def runAsync(func, *args, **kw):
    from twisted.internet import reactor