Skip to content

Commit bd37883

Browse files
committed
Code quality
1 parent 011500e commit bd37883

6 files changed

Lines changed: 77 additions & 18 deletions

File tree

dev/powinterrupttest.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
Code for discovering how C PoW can be interrupted
3+
"""
14
import ctypes
25
import hashlib
36
from multiprocessing import current_process
@@ -9,9 +12,12 @@
912
shutdown = 0
1013

1114

12-
def signal_handler(signal, frame):
13-
global shutdown
14-
print("Got signal %i in %s/%s" % (signal, current_process().name, current_thread().name))
15+
# pylint: disable=unused-argument
16+
def signal_handler(signum, frame):
17+
"""Signal handler"""
18+
global shutdown # pylint: disable=global-statement
19+
print("Got signal %i in %s/%s" % (signum, current_process().name,
20+
current_thread().name))
1521
if current_process().name != "MainProcess":
1622
raise StopIteration("Interrupted")
1723
if current_thread().name != "PyBitmessage":
@@ -31,7 +37,12 @@ def _doCPoW(target, initialHash):
3137
nonce = bmpow(out_h, out_m)
3238
if shutdown:
3339
break
34-
trialValue, = unpack('>Q', hashlib.sha512(hashlib.sha512(pack('>Q', nonce) + initialHash).digest()).digest()[0:8])
40+
trialValue, = unpack('>Q',
41+
hashlib.sha512(
42+
hashlib.sha512(
43+
pack('>Q', nonce) + initialHash).
44+
digest()).
45+
digest()[0:8])
3546
if shutdown != 0:
3647
raise StopIteration("Interrupted")
3748
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 on 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 -----------------------------------------------------

packages/collectd/pybitmessagestatus.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
#!/usr/bin/env python2.7
2+
"""
3+
PyBitmessage status module for collectd
4+
Provides values for active connections and processed objects
5+
"""
26

37
import json
48

5-
import collectd
9+
import collectd # pylint: disable=import-error
610
from six.moves import xmlrpc_client as xmlrpclib
711

812
pybmurl = ""
9-
api = ""
13+
api = None
1014

1115

1216
def init_callback():
13-
global api
17+
"""
18+
Initialise callback
19+
Creates an API object
20+
"""
21+
global api # pylint: disable=global-statement
1422
api = xmlrpclib.ServerProxy(pybmurl)
1523
collectd.info('pybitmessagestatus.py init done')
1624

1725

1826
def config_callback(ObjConfiguration):
19-
global pybmurl
27+
"""
28+
Load module config
29+
"""
30+
global pybmurl # pylint: disable=global-statement
2031
apiUsername = ""
2132
apiPassword = ""
2233
apiInterface = "127.0.0.1"
@@ -31,11 +42,17 @@ def config_callback(ObjConfiguration):
3142
apiInterface = node.values[0]
3243
elif key.lower() == "apiport" and node.values:
3344
apiPort = node.values[0]
34-
pybmurl = "http://{}:{}@{}:{}/".format(apiUsername, apiPassword, apiInterface, str(int(apiPort)))
45+
pybmurl = "http://{}:{}@{}:{}/".format(apiUsername,
46+
apiPassword,
47+
apiInterface,
48+
str(int(apiPort)))
3549
collectd.info('pybitmessagestatus.py config done')
3650

3751

3852
def read_callback():
53+
"""
54+
Read data from API
55+
"""
3956
try:
4057
clientStatus = json.loads(api.clientStatus())
4158
except (ValueError, TypeError):

packages/pyinstaller/hooks/pyinstaller_rthook_plugins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Runtime PyInstaller hook to load plugins"""
22

3+
# pylint: disable=unused-import
34
import os
45
import sys
56

src/bitmessagecurses/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# * python2-pythondialog
1111
# * dialog
1212

13+
# pylint: disable=global-statement,too-many-lines
1314
import ConfigParser
1415
import curses
1516
import os
@@ -31,7 +32,6 @@
3132
from bmconfigparser import config
3233
from helper_sql import sqlExecute, sqlQuery
3334

34-
# pylint: disable=global-statement
3535

3636

3737
quit_ = False

0 commit comments

Comments
 (0)