Skip to content

Commit d5b766f

Browse files
committed
tls pylint fixes
1 parent c5da630 commit d5b766f

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/network/tls.py

Lines changed: 24 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,8 @@ def __init__(
6062
self.isSSL = False
6163

6264
def state_tls_init(self):
65+
"""Prepare sockets for TLS handshake"""
66+
# pylint: disable=attribute-defined-outside-init
6367
self.isSSL = True
6468
self.tlsStarted = True
6569
# Once the connection has been established, it's safe to wrap the
@@ -89,10 +93,13 @@ def state_tls_init(self):
8993
# if hasattr(self.socket, "context"):
9094
# self.socket.context.set_ecdh_curve("secp256k1")
9195

92-
def state_tls_handshake(self):
96+
@staticmethod
97+
def state_tls_handshake():
98+
"""Do nothing while TLS handshake is pending, as during this phase we need to react to callbacks instead"""
9399
return False
94100

95101
def writable(self):
102+
"""Handle writable checks for TLS-enabled sockets"""
96103
try:
97104
if self.tlsStarted and not self.tlsDone and not self.write_buf:
98105
return self.want_write
@@ -101,6 +108,7 @@ def writable(self):
101108
return AdvancedDispatcher.writable(self)
102109

103110
def readable(self):
111+
"""Handle readable check for TLS-enabled sockets"""
104112
try:
105113
# during TLS handshake, and after flushing write buffer, return status of last handshake attempt
106114
if self.tlsStarted and not self.tlsDone and not self.write_buf:
@@ -113,7 +121,11 @@ def readable(self):
113121
except AttributeError:
114122
return AdvancedDispatcher.readable(self)
115123

116-
def handle_read(self):
124+
def handle_read(self): # pylint: disable=inconsistent-return-statements
125+
"""
126+
Handle reads for sockets during TLS handshake. Requires special treatment as during the handshake, buffers must
127+
remain empty and normal reads must be ignored
128+
"""
117129
try:
118130
# wait for write buffer flush
119131
if self.tlsStarted and not self.tlsDone and not self.write_buf:
@@ -134,7 +146,11 @@ def handle_read(self):
134146
self.handle_close()
135147
return
136148

137-
def handle_write(self):
149+
def handle_write(self): # pylint: disable=inconsistent-return-statements
150+
"""
151+
Handle writes for sockets during TLS handshake. Requires special treatment as during the handshake, buffers
152+
must remain empty and normal writes must be ignored
153+
"""
138154
try:
139155
# wait for write buffer flush
140156
if self.tlsStarted and not self.tlsDone and not self.write_buf:
@@ -156,6 +172,7 @@ def handle_write(self):
156172
return
157173

158174
def tls_handshake(self):
175+
"""Perform TLS handshake and handle its stages"""
159176
# wait for flush
160177
if self.write_buf:
161178
return False
@@ -175,7 +192,7 @@ def tls_handshake(self):
175192
if not (self.want_write or self.want_read):
176193
raise
177194
except socket.error as err:
178-
if err.errno in asyncore._DISCONNECTED:
195+
if err.errno in asyncore._DISCONNECTED: # pylint: disable=protected-access
179196
self.handle_close()
180197
else:
181198
raise

0 commit comments

Comments
 (0)