Skip to content

Commit 0a790d9

Browse files
committed
tls pylint fixes
1 parent c5da630 commit 0a790d9

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/network/tls.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@
3838
sslProtocolCiphers = "AECDH-AES256-SHA"
3939

4040

41-
class TLSDispatcher(AdvancedDispatcher):
41+
class TLSDispatcher(AdvancedDispatcher): # pylint: disable=too-many-instance-attributes
42+
"""TLS functionality for classes derived from AdvancedDispatcher"""
43+
# pylint: disable=too-many-arguments, super-init-not-called, unused-argument
4244
def __init__(
43-
self, address=None, sock=None, certfile=None, keyfile=None,
44-
server_side=False, ciphers=sslProtocolCiphers
45+
self, address=None, sock=None, certfile=None, keyfile=None,
46+
server_side=False, ciphers=sslProtocolCiphers
4547
):
4648
self.want_read = self.want_write = True
4749
if certfile is None:
@@ -60,6 +62,11 @@ def __init__(
6062
self.isSSL = False
6163

6264
def state_tls_init(self):
65+
"""
66+
Prepare sockets for TLS handshake
67+
.. todo:: standardize which curves are used.
68+
"""
69+
# pylint: disable=attribute-defined-outside-init
6370
self.isSSL = True
6471
self.tlsStarted = True
6572
# Once the connection has been established, it's safe to wrap the
@@ -89,10 +96,13 @@ def state_tls_init(self):
8996
# if hasattr(self.socket, "context"):
9097
# self.socket.context.set_ecdh_curve("secp256k1")
9198

92-
def state_tls_handshake(self):
99+
@staticmethod
100+
def state_tls_handshake():
101+
"""Do nothing while TLS handshake is pending, as during this phase we need to react to callbacks instead"""
93102
return False
94103

95104
def writable(self):
105+
"""Handle writable checks for TLS-enabled sockets"""
96106
try:
97107
if self.tlsStarted and not self.tlsDone and not self.write_buf:
98108
return self.want_write
@@ -101,6 +111,7 @@ def writable(self):
101111
return AdvancedDispatcher.writable(self)
102112

103113
def readable(self):
114+
"""Handle readable check for TLS-enabled sockets"""
104115
try:
105116
# during TLS handshake, and after flushing write buffer, return status of last handshake attempt
106117
if self.tlsStarted and not self.tlsDone and not self.write_buf:
@@ -113,7 +124,11 @@ def readable(self):
113124
except AttributeError:
114125
return AdvancedDispatcher.readable(self)
115126

116-
def handle_read(self):
127+
def handle_read(self): # pylint: disable=inconsistent-return-statements
128+
"""
129+
Handle reads for sockets during TLS handshake. Requires special treatment as during the handshake, buffers must
130+
remain empty and normal reads must be ignored
131+
"""
117132
try:
118133
# wait for write buffer flush
119134
if self.tlsStarted and not self.tlsDone and not self.write_buf:
@@ -134,7 +149,11 @@ def handle_read(self):
134149
self.handle_close()
135150
return
136151

137-
def handle_write(self):
152+
def handle_write(self): # pylint: disable=inconsistent-return-statements
153+
"""
154+
Handle writes for sockets during TLS handshake. Requires special treatment as during the handshake, buffers
155+
must remain empty and normal writes must be ignored
156+
"""
138157
try:
139158
# wait for write buffer flush
140159
if self.tlsStarted and not self.tlsDone and not self.write_buf:
@@ -156,6 +175,7 @@ def handle_write(self):
156175
return
157176

158177
def tls_handshake(self):
178+
"""Perform TLS handshake and handle its stages"""
159179
# wait for flush
160180
if self.write_buf:
161181
return False
@@ -175,7 +195,7 @@ def tls_handshake(self):
175195
if not (self.want_write or self.want_read):
176196
raise
177197
except socket.error as err:
178-
if err.errno in asyncore._DISCONNECTED:
198+
if err.errno in asyncore._DISCONNECTED: # pylint: disable=protected-access
179199
self.handle_close()
180200
else:
181201
raise

0 commit comments

Comments
 (0)