Skip to content

Commit 783f3cc

Browse files
committed
Document Transport class
1 parent 5b7014d commit 783f3cc

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎docs/transport.rst‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
Transport class
22
--------------
33

4-
.. automodule:: trezorlib.transport
4+
.. autoclass:: trezorlib.transport.Transport
5+
:members:
6+
:undoc-members:
7+
8+
Exceptions:
9+
10+
.. autoclass:: trezorlib.transport.ConnectionError
11+
:members:
12+
:undoc-members:
13+
14+
.. autoclass:: trezorlib.transport.NotImplementedException
515
:members:
616
:undoc-members:

‎trezorlib/transport.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,47 @@ def _session_end(self):
3232
pass
3333

3434
def ready_to_read(self):
35+
"""
36+
Returns True if there is data to be read from the transport. Otherwise, False.
37+
"""
3538
raise NotImplementedException("Not implemented")
3639

3740
def session_begin(self):
41+
"""
42+
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.
43+
"""
3844
if self.session_depth == 0:
3945
self._session_begin()
4046
self.session_depth += 1
4147

4248
def session_end(self):
49+
"""
50+
End a session. Se session_begin for an in depth description of TREZOR sessions.
51+
"""
4352
self.session_depth -= 1
4453
self.session_depth = max(0, self.session_depth)
4554
if self.session_depth == 0:
4655
self._session_end()
4756

4857
def close(self):
58+
"""
59+
Close the connection to the physical device or file descriptor represented by the Transport.
60+
"""
4961
self._close()
5062

5163
def write(self, msg):
64+
"""
65+
Write mesage to tansport. msg should be a member of a valid `protobuf class <https://developers.google.com/protocol-buffers/docs/pythontutorial>`_ with a SerializeToString() method.
66+
"""
5267
ser = msg.SerializeToString()
5368
header = struct.pack(">HL", mapping.get_type(msg), len(ser))
5469
self._write("##%s%s" % (header, ser), msg)
5570

5671
def read(self):
72+
"""
73+
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.
74+
Otherwise, returns None.
75+
"""
5776
if not self.ready_to_read():
5877
return None
5978

@@ -64,6 +83,9 @@ def read(self):
6483
return self._parse_message(data)
6584

6685
def read_blocking(self):
86+
"""
87+
Same as read, except blocks untill data is available to be read.
88+
"""
6789
while True:
6890
data = self._read()
6991
if data != None:

0 commit comments

Comments
 (0)