Skip to content

Commit c104c59

Browse files
committed
Code quality
1 parent 011500e commit c104c59

3 files changed

Lines changed: 54 additions & 12 deletions

File tree

dev/powinterrupttest.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Code for discovering how C PoW can be interrupted
3+
4+
"""
15
import ctypes
26
import hashlib
37
from multiprocessing import current_process
@@ -9,9 +13,12 @@
913
shutdown = 0
1014

1115

12-
def signal_handler(signal, frame):
13-
global shutdown
14-
print("Got signal %i in %s/%s" % (signal, current_process().name, current_thread().name))
16+
# pylint: disable=unused-argument
17+
def signal_handler(signum, frame):
18+
"""Signal handler"""
19+
global shutdown # pylint: disable=global-statement
20+
print("Got signal %i in %s/%s" % (signum, current_process().name,
21+
current_thread().name))
1522
if current_process().name != "MainProcess":
1623
raise StopIteration("Interrupted")
1724
if current_thread().name != "PyBitmessage":
@@ -31,7 +38,12 @@ def _doCPoW(target, initialHash):
3138
nonce = bmpow(out_h, out_m)
3239
if shutdown:
3340
break
34-
trialValue, = unpack('>Q', hashlib.sha512(hashlib.sha512(pack('>Q', nonce) + initialHash).digest()).digest()[0:8])
41+
trialValue, = unpack('>Q',
42+
hashlib.sha512(
43+
hashlib.sha512(
44+
pack('>Q', nonce) + initialHash).
45+
digest()).
46+
digest()[0:8])
3547
if shutdown != 0:
3648
raise StopIteration("Interrupted")
3749
print("C PoW done")

dev/ssltest.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
Development code for SSL compatibility investigations
3+
"""
14
import os
25
import select
36
import socket
@@ -9,8 +12,12 @@
912
PORT = 8912
1013

1114

15+
# pylint: disable=no-member
1216
def sslProtocolVersion():
13-
# sslProtocolVersion
17+
"""
18+
Find a protocol version value with compatibility across
19+
different python versions
20+
"""
1421
if sys.version_info >= (2, 7, 13):
1522
# this means TLSv1 or higher
1623
# in the future change to
@@ -26,26 +33,42 @@ def sslProtocolVersion():
2633

2734

2835
def sslProtocolCiphers():
36+
"""
37+
Find protocol cipher that is compatible for PyBitmessage across
38+
different python and OpenSSL versions
39+
"""
2940
if ssl.OPENSSL_VERSION_NUMBER >= 0x10100000:
3041
return "AECDH-AES256-SHA@SECLEVEL=0"
3142
else:
3243
return "AECDH-AES256-SHA"
3344

3445

46+
# pylint: disable=redefined-outer-name
3547
def connect():
48+
"""
49+
Connect a socket
50+
"""
3651
sock = socket.create_connection((HOST, PORT))
3752
return sock
3853

3954

55+
# pylint: disable=redefined-outer-name
4056
def listen():
57+
"""
58+
Listen to a socket
59+
"""
4160
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4261
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
4362
sock.bind((HOST, PORT))
4463
sock.listen(0)
4564
return sock
4665

4766

67+
# pylint: disable=redefined-outer-name
4868
def sslHandshake(sock, server=False):
69+
"""
70+
Perform SSL hadnshake
71+
"""
4972
if sys.version_info >= (2, 7, 9):
5073
context = ssl.SSLContext(sslProtocolVersion())
5174
context.set_ciphers(sslProtocolCiphers())
@@ -54,12 +77,19 @@ def sslHandshake(sock, server=False):
5477
context.verify_mode = ssl.CERT_NONE
5578
context.options = ssl.OP_ALL | ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3\
5679
| ssl.OP_SINGLE_ECDH_USE | ssl.OP_CIPHER_SERVER_PREFERENCE
57-
sslSock = context.wrap_socket(sock, server_side=server, do_handshake_on_connect=False)
80+
sslSock = context.wrap_socket(sock, server_side=server,
81+
do_handshake_on_connect=False)
5882
else:
59-
sslSock = ssl.wrap_socket(sock, keyfile=os.path.join('src', 'sslkeys', 'key.pem'),
60-
certfile=os.path.join('src', 'sslkeys', 'cert.pem'),
61-
server_side=server, ssl_version=sslProtocolVersion(),
62-
do_handshake_on_connect=False, ciphers='AECDH-AES256-SHA')
83+
sslSock = ssl.wrap_socket(sock, keyfile=os.path.join('src',
84+
'sslkeys',
85+
'key.pem'),
86+
certfile=os.path.join('src',
87+
'sslkeys',
88+
'cert.pem'),
89+
server_side=server,
90+
ssl_version=sslProtocolVersion(),
91+
do_handshake_on_connect=False,
92+
ciphers='AECDH-AES256-SHA')
6393

6494
while True:
6595
try:

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
sys.path.insert(0, os.path.abspath('../src'))
1515

16-
from importlib import import_module
16+
from importlib import import_module # pylint: disable=wrong-import-position
1717

18-
import version # noqa:E402
18+
import version # noqa:E402 pylint: disable=wrong-import-position
1919

2020

2121
# -- Project information -----------------------------------------------------

0 commit comments

Comments
 (0)