diff --git a/docs/transport.rst b/docs/transport.rst index 929103710..e774d5650 100644 --- a/docs/transport.rst +++ b/docs/transport.rst @@ -1,6 +1,16 @@ Transport class -------------- -.. automodule:: trezorlib.transport +.. autoclass:: trezorlib.transport.Transport + :members: + :undoc-members: + +Exceptions: + +.. autoclass:: trezorlib.transport.ConnectionError + :members: + :undoc-members: + +.. autoclass:: trezorlib.transport.NotImplementedException :members: :undoc-members: \ No newline at end of file diff --git a/trezorlib/transport.py b/trezorlib/transport.py index 63f0c729e..71160f0f4 100644 --- a/trezorlib/transport.py +++ b/trezorlib/transport.py @@ -32,28 +32,47 @@ class Transport(object): pass def ready_to_read(self): + """ + Returns True if there is data to be read from the transport. Otherwise, False. + """ raise NotImplementedException("Not implemented") def session_begin(self): + """ + Apply a lock to the device in order to preform synchronous multistep "conversations" with the device. For example, before entering the transaction signing workflow, one begins a session. After the transaction is complete, the session may be ended. + """ if self.session_depth == 0: self._session_begin() self.session_depth += 1 def session_end(self): + """ + End a session. Se session_begin for an in depth description of TREZOR sessions. + """ self.session_depth -= 1 self.session_depth = max(0, self.session_depth) if self.session_depth == 0: self._session_end() def close(self): + """ + Close the connection to the physical device or file descriptor represented by the Transport. + """ self._close() def write(self, msg): + """ + Write mesage to tansport. msg should be a member of a valid `protobuf class `_ with a SerializeToString() method. + """ ser = msg.SerializeToString() header = struct.pack(">HL", mapping.get_type(msg), len(ser)) self._write("##%s%s" % (header, ser), msg) def read(self): + """ + If there is data available to be read from the transport, reads the data and tries to parse it as a protobuf message. If the parsing succeeds, return a protobuf object. + Otherwise, returns None. + """ if not self.ready_to_read(): return None @@ -64,6 +83,9 @@ class Transport(object): return self._parse_message(data) def read_blocking(self): + """ + Same as read, except blocks untill data is available to be read. + """ while True: data = self._read() if data != None: