Skip to content

Commit

Permalink
Add docstrings for protocol and server methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
maffoo committed Dec 22, 2015
1 parent 697f258 commit 4ac16f5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
31 changes: 26 additions & 5 deletions labrad/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def removeListener(self, listener, source=None, context=None, ID=None):

@inlineCallbacks
def authenticate(self, password):
"""Implements the LabRAD login protocol."""
"""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
Expand All @@ -321,11 +321,33 @@ def authenticate(self, password):
self.loginMessage = resp[0][1] # get welcome message

def loginClient(self, name):
"""Log in as a client."""
"""Log in as a client by sending our name to the manager.
Args:
name (str): The name of this labrad connection. Need not be unique.
Returns:
twisted.internet.defer.Deferred(None): A deferred that will fire
after we have logged in.
"""
return self._doLogin(name)

def loginServer(self, name, descr, notes):
"""Log in as a server."""
"""Log in as a server by sending our name and metadata to the manager.
Args:
name (str): The name of this server. Must be unique; login will
fail if another server of the same name is already connected.
descr (str): A description of this server, which will be exposed
to other labrad clients.
notes (str): More descriptive information about the server. This
field is deprecated; instead we recommend just putting all info
into descr.
Returns:
twisted.internet.defer.Deferred(None): A deferred that will fire
after we have logged in.
"""
return self._doLogin(name, descr, notes)

@inlineCallbacks
Expand Down Expand Up @@ -369,8 +391,7 @@ def connect(host=C.MANAGER_HOST, port=None, tls=C.MANAGER_TLS):
Returns:
twisted.internet.defer.Deferred(LabradProtocol): A deferred that will
fire with the protocol once the connection is established, or will
errback if the connection fails.
fire with the protocol once the connection is established.
"""
tls = C.check_tls_mode(tls)
if port is None:
Expand Down
16 changes: 16 additions & 0 deletions labrad/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,22 @@ def removeSignal(self, signal, packet=None):

@inlineCallbacks
def startup(self, protocol):
"""Start this server using the given protocol connection.
Identifies this server to the manager, creates an async wrapper for the
protocol connection, and then runs initialization callbacks for this
server.
Args:
protocol (labrad.protocol.LabradProtocol): A protocol connection
to the labrad manager, as returned by labrad.protocol.connect.
This protocol must have been authenticated prior to calling
startup.
Returns:
twisted.internet.defer.Deferred(None): A deferred that will fire
once startup is complete.
"""
try:
name = getattr(self, 'instanceName', self.name)
yield protocol.loginServer(name, self.description, self.notes)
Expand Down

0 comments on commit 4ac16f5

Please sign in to comment.