code fixes for PR#11

This commit is contained in:
lakshyacis 2019-09-17 20:14:26 +05:30
parent 1177e17c81
commit 69f8d50f81
No known key found for this signature in database
GPG Key ID: D2C539C8EC63E9EB
4 changed files with 90 additions and 51 deletions

View File

@ -1,5 +1,7 @@
"""Coding: utf-8."""
# pylint: disable=relative-import, too-many-lines
"""
src/bitmessagekivy/mpybit.py
=================================
"""
import os
import time
from functools import partial
@ -53,7 +55,7 @@ import queues
from semaphores import kivyuisignaler
import state
from uikivysignaler import UIkivySignaler
# pylint: disable=unused-argument, too-few-public-methods
# pylint: disable=unused-argument, too-few-public-methods, import-error
if platform == 'linux':

View File

@ -1,3 +1,7 @@
"""
src/bitmessagemain.py
=================================
"""
# !/usr/bin/python2.7
# Copyright (c) 2012-2016 Jonathan Warren
# Copyright (c) 2012-2019 The Bitmessage developers
@ -11,16 +15,6 @@
import os
import sys
app_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(app_dir)
sys.path.insert(0, app_dir)
import depends
depends.check_dependencies()
import ctypes
import getopt
import multiprocessing
@ -38,6 +32,7 @@ from helper_startup import (
from singleinstance import singleinstance
import defaults
import depends
import shared
import knownnodes
import state
@ -67,8 +62,15 @@ from network.uploadthread import UploadThread
# Helper Functions
import helper_threading
app_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(app_dir)
sys.path.insert(0, app_dir)
depends.check_dependencies()
def connectToStream(streamNumber):
"""Connecting to stream"""
state.streamsInWhichIAmParticipating.append(streamNumber)
if isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
@ -109,6 +111,7 @@ def _fixSocket():
addressToString = ctypes.windll.ws2_32.WSAAddressToStringA
def inet_ntop(family, host):
"""inet ntop"""
if family == socket.AF_INET:
if len(host) != 4:
raise ValueError("invalid IPv4 host")
@ -130,6 +133,7 @@ def _fixSocket():
stringToAddress = ctypes.windll.ws2_32.WSAStringToAddressA
def inet_pton(family, host):
"""inet pton"""
buf = "\0" * 28
lengthBuf = pack("I", len(buf))
if stringToAddress(str(host),
@ -175,16 +179,18 @@ def signal_handler(signum, frame):
if shared.thisapp.daemon or not state.enableGUI:
shutdown.doCleanShutdown()
else:
print('# Thread: %s(%d)' % (thread.name, thread.ident))
print '# Thread: %s(%d)' % (thread.name, thread.ident)
for filename, lineno, name, line in traceback.extract_stack(frame):
print('File: "%s", line %d, in %s' % (filename, lineno, name))
print 'File: "%s", line %d, in %s' % (filename, lineno, name)
if line:
print(' %s' % line.strip())
print('Unfortunately you cannot use Ctrl+C when running the UI'
' because the UI captures the signal.')
print ' %s' % line.strip()
print 'Unfortunately you cannot use Ctrl+C when running the UI \
because the UI captures the signal.'
class Main:
class Main: # pylint: disable=no-init, old-style-class
"""Main Method"""
@staticmethod
def start_proxyconfig(config):
"""Check socksproxytype and start any proxy configuration plugin"""
@ -206,7 +212,8 @@ class Main:
'Started proxy config plugin %s in %s sec',
proxy_type, time.time() - proxyconfig_start)
def start(self):
def start(self): # pylint: disable=too-many-statements, too-many-branches, too-many-locals
"""Start the main method"""
_fixSocket()
config = BMConfigParser()
@ -274,7 +281,7 @@ class Main:
if daemon:
with shared.printLock:
print('Running as a daemon. Send TERM signal to end.')
print 'Running as a daemon. Send TERM signal to end.'
self.daemonize()
self.setSignalHandler()
@ -397,7 +404,7 @@ class Main:
if state.curses:
if not depends.check_curses():
sys.exit()
print('Running with curses')
print 'Running with curses'
import bitmessagecurses
bitmessagecurses.runwrapper()
@ -415,8 +422,7 @@ class Main:
if daemon:
while state.shutdown == 0:
time.sleep(1)
if (
state.testmode and time.time() - state.last_api_response >= 30):
if (state.testmode and time.time() - state.last_api_response >= 30):
self.stop()
elif not state.enableGUI:
from tests import core as test_core # pylint: disable=relative-import
@ -430,7 +436,9 @@ class Main:
else 0
)
def daemonize(self):
@staticmethod
def daemonize():
"""Daemonize"""
grandfatherPid = os.getpid()
parentPid = None
try:
@ -440,7 +448,7 @@ class Main:
# wait until grandchild ready
while True:
time.sleep(1)
os._exit(0)
os._exit(0) # pylint: disable=protected-access
except AttributeError:
# fork not implemented
pass
@ -461,7 +469,7 @@ class Main:
# wait until child ready
while True:
time.sleep(1)
os._exit(0)
os._exit(0) # pylint: disable=protected-access
except AttributeError:
# fork not implemented
pass
@ -482,12 +490,15 @@ class Main:
os.kill(parentPid, signal.SIGTERM)
os.kill(grandfatherPid, signal.SIGTERM)
def setSignalHandler(self):
def setSignalHandler(self): # pylint: disable=no-self-use
"""Set Signal Handler"""
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
# signal.signal(signal.SIGINT, signal.SIG_DFL)
def usage(self):
@staticmethod
def usage():
"""getting usages"""
print 'Usage: ' + sys.argv[0] + ' [OPTIONS]'
print '''
Options:
@ -499,13 +510,15 @@ Options:
All parameters are optional.
'''
def stop(self):
def stop(self): # pylint: disable=no-self-use
"""Stopping Bitmessage Deamon"""
with shared.printLock:
print('Stopping Bitmessage Deamon.')
print 'Stopping Bitmessage Deamon.'
shutdown.doCleanShutdown()
# TODO: nice function but no one is using this
def getApiAddress(self):
# ..todo: nice function but no one is using this
def getApiAddress(self): # pylint: disable=no-self-use
"""Getting Api Addresses"""
if not BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'apienabled'):
return None
@ -515,6 +528,7 @@ All parameters are optional.
def main():
"""Start of main thread"""
mainprogram = Main()
mainprogram.start()

View File

@ -1,9 +1,15 @@
"""
src/identiconGeneration
=================================
"""
import hashlib
from PIL import Image
from kivy.core.image import Image as CoreImage
# Core classes for loading images and converting them to a Texture. The raw image data can be keep in memory for further access
from kivy.uix.image import Image as kiImage
from io import BytesIO
""" Core classes for loading images and converting them to a Texture.
The raw image data can be keep in memory for further access """
# constants
RESOLUTION = 128, 128
@ -13,6 +19,7 @@ MODE = "RGB"
def generate(Generate_string=None):
"""Generating string"""
hash_string = generate_hash(Generate_string)
color = random_color(hash_string)
image = Image.new(MODE, V_RESOLUTION, BACKGROUND_COLOR)
@ -32,20 +39,22 @@ def generate(Generate_string=None):
def generate_hash(string):
"""Generating hash"""
try:
# make input case insensitive
string = str.lower(string)
hash_object = hashlib.md5(str.encode(string))
print(hash_object.hexdigest())
print hash_object.hexdigest()
# returned object is a hex string
return hash_object.hexdigest()
except IndexError:
print("Error: Please enter a string as an argument.")
print "Error: Please enter a string as an argument."
def random_color(hash_string):
"""Getting random color"""
# remove first three digits from hex string
split = 6
rgb = hash_string[:split]
@ -62,6 +71,7 @@ def random_color(hash_string):
def generate_image(image, color, hash_string):
"""Generating images"""
hash_string = hash_string[6:]
lower_x = 1

View File

@ -1,3 +1,14 @@
"""
src/pyelliptic/openssl.py
=================================
"""
import sys
import ctypes
from kivy.utils import platform
OpenSSL = None
# !/usr/bin/env python
# -*- coding: utf-8 -*-
@ -6,13 +17,9 @@
#
# Software slightly changed by Jonathan Warren <bitmessage at-symbol jonwarren.org>
import sys
import ctypes
OpenSSL = None
from kivy.utils import platform
class CipherName:
class CipherName: # pylint: disable=old-style-class
"""Getting CipherName"""
def __init__(self, name, pointer, blocksize):
self._name = name
self._pointer = pointer
@ -24,16 +31,20 @@ class CipherName:
" | Function pointer : " + str(self._pointer)
def get_pointer(self):
"""Getting pointer"""
return self._pointer()
def get_name(self):
"""Getting Name"""
return self._name
def get_blocksize(self):
"""Getting blocksize"""
return self._blocksize
def get_version(library):
"""Getting versions"""
version = None
hexversion = None
cflags = None
@ -64,14 +75,11 @@ def get_version(library):
return (version, hexversion, cflags)
class _OpenSSL:
"""
Wrapper for OpenSSL using ctypes
"""
class _OpenSSL: # pylint: disable=too-many-instance-attributes, old-style-class, too-many-statements
"""Wrapper for OpenSSL using ctypes"""
def __init__(self, library):
"""
Build the wrapper
"""
"""Build the wrapper"""
self._lib = ctypes.CDLL(library)
self._version, self._hexversion, self._cflags = get_version(self._lib)
self._libreSSL = self._version.startswith("LibreSSL")
@ -594,6 +602,7 @@ class _OpenSSL:
"""
returns the name of a elliptic curve with his id
"""
# pylint: disable=redefined-builtin
res = None
for i in self.curves:
if self.curves[i] == id:
@ -607,6 +616,7 @@ class _OpenSSL:
"""
OpenSSL random function
"""
# pylint: disable=redefined-builtin
buffer = self.malloc(0, size)
# This pyelliptic library, by default, didn't check the return value of RAND_bytes. It is
# evidently possible that it returned an error and not-actually-random data. However, in
@ -623,6 +633,7 @@ class _OpenSSL:
"""
returns a create_string_buffer (ctypes)
"""
# pylint: disable=redefined-builtin
buffer = None
if data != 0:
if sys.version_info.major == 3 and isinstance(data, type('')):
@ -634,6 +645,8 @@ class _OpenSSL:
def loadOpenSSL():
"""Loading OpenSSL"""
# pylint: disable=global-statement, protected-access, too-many-branches
global OpenSSL
from os import path, environ
from ctypes.util import find_library