From 24b83aae2aed88ade5a95729ee786b7f3ef71b9a Mon Sep 17 00:00:00 2001 From: Kashiko Koibumi Date: Fri, 17 May 2024 01:53:27 +0900 Subject: [PATCH] run autopep8 on src --- run-autopep8.sh | 2 ++ src/api.py | 1 + src/backend/address_generator.py | 1 + src/bitmessagemain.py | 43 +++++++++++++++--------------- src/bmconfigparser.py | 2 +- src/class_objectProcessor.py | 1 + src/class_singleWorker.py | 8 +++--- src/class_smtpServer.py | 3 +++ src/depends.py | 2 +- src/helper_msgcoding.py | 3 +++ src/inventory.py | 1 + src/messagetypes/message.py | 1 + src/network/__init__.py | 2 +- src/network/asyncore_pollchoose.py | 6 ++--- src/network/dandelion.py | 1 + src/network/httpd.py | 1 + src/network/objectracker.py | 2 +- src/network/receivequeuethread.py | 1 + src/network/socks4a.py | 3 +++ src/network/socks5.py | 3 +++ src/network/tls.py | 2 ++ src/pyelliptic/cipher.py | 1 + src/pyelliptic/openssl.py | 1 + src/qidenticon.py | 1 + src/singleinstance.py | 1 + src/storage/sqlite.py | 1 + src/tr.py | 1 + 27 files changed, 63 insertions(+), 32 deletions(-) create mode 100755 run-autopep8.sh diff --git a/run-autopep8.sh b/run-autopep8.sh new file mode 100755 index 00000000..e879318f --- /dev/null +++ b/run-autopep8.sh @@ -0,0 +1,2 @@ +#!/bin/sh +autopep8 --in-place --recursive src diff --git a/src/api.py b/src/api.py index a4445569..be2a64dd 100644 --- a/src/api.py +++ b/src/api.py @@ -328,6 +328,7 @@ class testmode(object): # pylint: disable=too-few-public-methods class command(object): # pylint: disable=too-few-public-methods """Decorator for API command method""" + def __init__(self, *aliases): self.aliases = aliases diff --git a/src/backend/address_generator.py b/src/backend/address_generator.py index 312c313b..f5455a42 100644 --- a/src/backend/address_generator.py +++ b/src/backend/address_generator.py @@ -12,6 +12,7 @@ from pybitmessage.defaults import ( class AddressGenerator(object): """"Base class for address generation and validation""" + def __init__(self): pass diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index f51ee063..4d8ea61d 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -9,6 +9,27 @@ The PyBitmessage startup script # Right now, PyBitmessage only support connecting to stream 1. It doesn't # yet contain logic to expand into further streams. +from threads import ( + set_thread_name, printLock, + addressGenerator, objectProcessor, singleCleaner, singleWorker, sqlThread) +from singleinstance import singleinstance +from inventory import Inventory +from helper_startup import ( + adjustHalfOpenConnectionsLimit, fixSocket, start_proxyconfig) +from debug import logger # this should go before any threads +from bmconfigparser import config +from testmode_init import populate_api_test_data +import state +import shutdown +import network +import defaults +import traceback +import time +import threading +import signal +import multiprocessing +import getopt +import depends import os import sys @@ -18,34 +39,13 @@ except ImportError: from pybitmessage import pathmagic app_dir = pathmagic.setup() -import depends depends.check_dependencies() -import getopt -import multiprocessing # Used to capture a Ctrl-C keypress so that Bitmessage can shutdown gracefully. -import signal -import threading -import time -import traceback -import defaults # Network subsystem -import network -import shutdown -import state -from testmode_init import populate_api_test_data -from bmconfigparser import config -from debug import logger # this should go before any threads -from helper_startup import ( - adjustHalfOpenConnectionsLimit, fixSocket, start_proxyconfig) -from inventory import Inventory -from singleinstance import singleinstance # Synchronous threads -from threads import ( - set_thread_name, printLock, - addressGenerator, objectProcessor, singleCleaner, singleWorker, sqlThread) def signal_handler(signum, frame): @@ -81,6 +81,7 @@ def signal_handler(signum, frame): class Main(object): """Main PyBitmessage class""" + def start(self): """Start main application""" # pylint: disable=too-many-statements,too-many-branches,too-many-locals diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index abf285ad..1062e630 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -128,7 +128,7 @@ class BMConfigParser(SafeConfigParser): shutil.copyfile(fileName, fileNameBak) # The backup succeeded. fileNameExisted = True - except(IOError, Exception): + except (IOError, Exception): # The backup failed. This can happen if the file # didn't exist before. fileNameExisted = False diff --git a/src/class_objectProcessor.py b/src/class_objectProcessor.py index 1a71f929..394601be 100644 --- a/src/class_objectProcessor.py +++ b/src/class_objectProcessor.py @@ -43,6 +43,7 @@ class objectProcessor(threading.Thread): The objectProcessor thread, of which there is only one, receives network objects (msg, broadcast, pubkey, getpubkey) from the receiveDataThreads. """ + def __init__(self): threading.Thread.__init__(self, name="objectProcessor") random.seed() diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py index 7a41f3c1..8392e8d1 100644 --- a/src/class_singleWorker.py +++ b/src/class_singleWorker.py @@ -1080,10 +1080,10 @@ class singleWorker(StoppableThread): " more difficult than you are" " willing to do. {2}" ).format(str(float(requiredAverageProofOfWorkNonceTrialsPerByte) - / defaults.networkDefaultProofOfWorkNonceTrialsPerByte), - str(float(requiredPayloadLengthExtraBytes) - / defaults.networkDefaultPayloadLengthExtraBytes), - l10n.formatTimestamp())))) + / defaults.networkDefaultProofOfWorkNonceTrialsPerByte), + str(float(requiredPayloadLengthExtraBytes) + / defaults.networkDefaultPayloadLengthExtraBytes), + l10n.formatTimestamp())))) continue else: # if we are sending a message to ourselves or a chan.. self.logger.info('Sending a message.') diff --git a/src/class_smtpServer.py b/src/class_smtpServer.py index 44ea7c9c..e925bf3f 100644 --- a/src/class_smtpServer.py +++ b/src/class_smtpServer.py @@ -35,6 +35,7 @@ class SmtpServerChannelException(Exception): class smtpServerChannel(smtpd.SMTPChannel): """Asyncore channel for SMTP protocol (server)""" + def smtp_EHLO(self, arg): """Process an EHLO""" if not arg: @@ -73,6 +74,7 @@ class smtpServerChannel(smtpd.SMTPChannel): class smtpServerPyBitmessage(smtpd.SMTPServer): """Asyncore SMTP server class""" + def handle_accept(self): """Accept a connection""" pair = self.accept() @@ -180,6 +182,7 @@ class smtpServerPyBitmessage(smtpd.SMTPServer): class smtpServer(StoppableThread): """SMTP server thread""" + def __init__(self, _=None): super(smtpServer, self).__init__(name="smtpServerThread") self.server = smtpServerPyBitmessage(('127.0.0.1', LISTENPORT), None) diff --git a/src/depends.py b/src/depends.py index 3f08f4d3..39337776 100755 --- a/src/depends.py +++ b/src/depends.py @@ -436,7 +436,7 @@ def check_dependencies(verbose=False, optional=False): if sys.hexversion < 0x3000000: logger.error( 'PyBitmessage requires Python 3 or greater') - #has_all_dependencies = False + # has_all_dependencies = False sys.exit() # FIXME: This needs to be uncommented when more of the code is python3 compatible diff --git a/src/helper_msgcoding.py b/src/helper_msgcoding.py index 225f352c..9c2652d6 100644 --- a/src/helper_msgcoding.py +++ b/src/helper_msgcoding.py @@ -37,12 +37,14 @@ class MsgDecodeException(Exception): class DecompressionSizeException(MsgDecodeException): # pylint: disable=super-init-not-called """Decompression resulted in too much data (attack protection)""" + def __init__(self, size): self.size = size class MsgEncode(object): """Message encoder class""" + def __init__(self, message, encoding=BITMESSAGE_ENCODING_SIMPLE): self.data = None self.encoding = encoding @@ -86,6 +88,7 @@ class MsgEncode(object): class MsgDecode(object): """Message decoder class""" + def __init__(self, encoding, data): self.encoding = encoding if self.encoding == BITMESSAGE_ENCODING_EXTENDED: diff --git a/src/inventory.py b/src/inventory.py index 8356262c..ccdf245d 100644 --- a/src/inventory.py +++ b/src/inventory.py @@ -21,6 +21,7 @@ class Inventory: Inventory class which uses storage backends to manage the inventory. """ + def __init__(self): self._moduleName = config.safeGet("inventory", "storage") self._realInventory = create_inventory_instance(self._moduleName) diff --git a/src/messagetypes/message.py b/src/messagetypes/message.py index 245c753f..5989d41c 100644 --- a/src/messagetypes/message.py +++ b/src/messagetypes/message.py @@ -5,6 +5,7 @@ logger = logging.getLogger('default') class MsgBase(object): # pylint: disable=too-few-public-methods """Base class for message types""" + def __init__(self): self.data = {"": type(self).__name__.lower()} diff --git a/src/network/__init__.py b/src/network/__init__.py index 1851e072..cc7bfb58 100644 --- a/src/network/__init__.py +++ b/src/network/__init__.py @@ -12,7 +12,7 @@ def start(config, state): """Start network threads""" import state from .announcethread import AnnounceThread - import network.connectionpool as connectionpool # pylint: disable=relative-import + import network.connectionpool as connectionpool # pylint: disable=relative-import from .addrthread import AddrThread from .dandelion import Dandelion from .downloadthread import DownloadThread diff --git a/src/network/asyncore_pollchoose.py b/src/network/asyncore_pollchoose.py index ccbe2aef..c8b9e364 100644 --- a/src/network/asyncore_pollchoose.py +++ b/src/network/asyncore_pollchoose.py @@ -564,12 +564,12 @@ class dispatcher(object): try: kqueue_poller.pollster.control([select.kevent( fd, select.KQ_FILTER_READ, select.KQ_EV_DELETE)], 0) - except(AttributeError, KeyError, TypeError, IOError, OSError): + except (AttributeError, KeyError, TypeError, IOError, OSError): pass try: kqueue_poller.pollster.control([select.kevent( fd, select.KQ_FILTER_WRITE, select.KQ_EV_DELETE)], 0) - except(AttributeError, KeyError, TypeError, IOError, OSError): + except (AttributeError, KeyError, TypeError, IOError, OSError): pass try: epoll_poller.pollster.unregister(fd) @@ -726,7 +726,7 @@ class dispatcher(object): # XXX unresolved # cheap inheritance, used to pass all other attribute # references to the underlying socket object. - #def __getattr__(self, attr): + # def __getattr__(self, attr): # try: # retattr = getattr(self.socket, attr) # except AttributeError: diff --git a/src/network/dandelion.py b/src/network/dandelion.py index 846b03e1..43f36857 100644 --- a/src/network/dandelion.py +++ b/src/network/dandelion.py @@ -28,6 +28,7 @@ logger = logging.getLogger('default') class Dandelion: # pylint: disable=old-style-class """Dandelion class for tracking stem/fluff stages.""" + def __init__(self): # currently assignable child stems self.stem = [] diff --git a/src/network/httpd.py b/src/network/httpd.py index 654566c2..a53d740c 100644 --- a/src/network/httpd.py +++ b/src/network/httpd.py @@ -69,6 +69,7 @@ class HTTPRequestHandler(asyncore.dispatcher): class HTTPSRequestHandler(HTTPRequestHandler, TLSHandshake): """Handling HTTPS request""" + def __init__(self, sock): if not hasattr(self, '_map'): asyncore.dispatcher.__init__(self, sock) # pylint: disable=non-parent-init-called diff --git a/src/network/objectracker.py b/src/network/objectracker.py index 63425def..0c3c752b 100644 --- a/src/network/objectracker.py +++ b/src/network/objectracker.py @@ -102,7 +102,7 @@ class ObjectTracker(object): def handleReceivedObject(self, streamNumber, hashid): """Handling received object""" - hashid_bytes = bytes(hashid); + hashid_bytes = bytes(hashid) for i in connectionpool.pool.connections(): if not i.fullyEstablished: continue diff --git a/src/network/receivequeuethread.py b/src/network/receivequeuethread.py index 68ad6124..3dafc15c 100644 --- a/src/network/receivequeuethread.py +++ b/src/network/receivequeuethread.py @@ -15,6 +15,7 @@ from .threads import StoppableThread class ReceiveQueueThread(StoppableThread): """This thread processes data received from the network (which is done by the asyncore thread)""" + def __init__(self, num=0): super(ReceiveQueueThread, self).__init__(name="ReceiveQueue_%i" % num) diff --git a/src/network/socks4a.py b/src/network/socks4a.py index 2758838a..0b16ded2 100644 --- a/src/network/socks4a.py +++ b/src/network/socks4a.py @@ -26,6 +26,7 @@ class Socks4aError(ProxyError): class Socks4a(Proxy): """SOCKS4a proxy class""" + def __init__(self, address=None): Proxy.__init__(self, address) self.ipaddr = None @@ -73,6 +74,7 @@ class Socks4a(Proxy): class Socks4aConnection(Socks4a): """Child SOCKS4a class used for making outbound connections.""" + def __init__(self, address): Socks4a.__init__(self, address=address) @@ -119,6 +121,7 @@ class Socks4aConnection(Socks4a): class Socks4aResolver(Socks4a): """DNS resolver class using SOCKS4a""" + def __init__(self, host): self.host = host self.port = 8444 diff --git a/src/network/socks5.py b/src/network/socks5.py index 1838a737..3542efc4 100644 --- a/src/network/socks5.py +++ b/src/network/socks5.py @@ -42,6 +42,7 @@ class Socks5Error(ProxyError): class Socks5(Proxy): """A socks5 proxy base class""" + def __init__(self, address=None): Proxy.__init__(self, address) self.ipaddr = None @@ -163,6 +164,7 @@ class Socks5(Proxy): class Socks5Connection(Socks5): """Child socks5 class used for making outbound connections.""" + def state_auth_done(self): """Request connection to be made""" # Now we can request the actual connection @@ -199,6 +201,7 @@ class Socks5Connection(Socks5): class Socks5Resolver(Socks5): """DNS resolver class using socks5""" + def __init__(self, host): self.host = host self.port = 8444 diff --git a/src/network/tls.py b/src/network/tls.py index 2f30fcc0..09841082 100644 --- a/src/network/tls.py +++ b/src/network/tls.py @@ -40,10 +40,12 @@ if ( else: sslProtocolCiphers = "AECDH-AES256-SHA" + class TLSDispatcher(AdvancedDispatcher): """TLS functionality for classes derived from AdvancedDispatcher""" # pylint: disable=too-many-instance-attributes, too-many-arguments # pylint: disable=super-init-not-called + def __init__(self, _=None, sock=None, certfile=None, keyfile=None, server_side=False, ciphers=sslProtocolCiphers): self.want_read = self.want_write = True diff --git a/src/pyelliptic/cipher.py b/src/pyelliptic/cipher.py index 2c2c54da..dedba3a9 100644 --- a/src/pyelliptic/cipher.py +++ b/src/pyelliptic/cipher.py @@ -22,6 +22,7 @@ class Cipher(object): ctx2 = pyelliptic.Cipher("secretkey", iv, 0, ciphername='aes-256-cfb') print ctx2.ciphering(ciphertext) """ + def __init__(self, key, iv, do, ciphername='aes-256-cbc'): """ do == 1 => Encrypt; do == 0 => Decrypt diff --git a/src/pyelliptic/openssl.py b/src/pyelliptic/openssl.py index deb81644..aadb3e7e 100644 --- a/src/pyelliptic/openssl.py +++ b/src/pyelliptic/openssl.py @@ -100,6 +100,7 @@ class _OpenSSL(object): Wrapper for OpenSSL using ctypes """ # pylint: disable=too-many-statements, too-many-instance-attributes + def __init__(self, library): """ Build the wrapper diff --git a/src/qidenticon.py b/src/qidenticon.py index 158a2232..92d0b64d 100644 --- a/src/qidenticon.py +++ b/src/qidenticon.py @@ -43,6 +43,7 @@ Returns an instance of :class:`QPixmap` which have generated identicon image. from six.moves import range from PyQt6 import QtCore, QtGui + class IdenticonRendererBase(object): """Encapsulate methods around rendering identicons""" diff --git a/src/singleinstance.py b/src/singleinstance.py index cff9d794..80eb411b 100644 --- a/src/singleinstance.py +++ b/src/singleinstance.py @@ -21,6 +21,7 @@ class singleinstance(object): Implements a single instance application by creating a lock file at appdata. """ + def __init__(self, flavor_id="", daemon=False): self.initialized = False self.counter = 0 diff --git a/src/storage/sqlite.py b/src/storage/sqlite.py index 6f810a16..38d9fd95 100644 --- a/src/storage/sqlite.py +++ b/src/storage/sqlite.py @@ -11,6 +11,7 @@ from .storage import InventoryItem, InventoryStorage class SqliteInventory(InventoryStorage): """Inventory using SQLite""" + def __init__(self): super(SqliteInventory, self).__init__() # of objects (like msg payloads and pubkey payloads) diff --git a/src/tr.py b/src/tr.py index 06e2e5d8..f26dcdff 100644 --- a/src/tr.py +++ b/src/tr.py @@ -15,6 +15,7 @@ class translateClass: when we are in daemon mode and not using any QT functions. """ # pylint: disable=old-style-class,too-few-public-methods + def __init__(self, context, text): self.context = context self.text = text