From e647d70bbcb450ab616f428374feb0de00866e77 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Tue, 6 Dec 2016 10:47:39 +0100 Subject: [PATCH] New config parser class - workaround for % in labels - can be extended in the future --- src/bitmessagecli.py | 15 ++++++++------- src/configparser.py | 7 +++++++ src/shared.py | 4 ++-- 3 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 src/configparser.py diff --git a/src/bitmessagecli.py b/src/bitmessagecli.py index ff5f091a..c7d8b5cd 100644 --- a/src/bitmessagecli.py +++ b/src/bitmessagecli.py @@ -5,7 +5,6 @@ # This is an example of a daemon client for PyBitmessage 0.4.2, by .dok (Version 0.3.0) -import ConfigParser import xmlrpclib import datetime import hashlib @@ -17,6 +16,8 @@ import time import sys import os +from configparser import BMConfigParser + api = '' keysName = 'keys.dat' keysPath = 'keys.dat' @@ -46,7 +47,7 @@ def restartBmNotify(): #Prompts the user to restart Bitmessage. def safeConfigGetBoolean(section,field): global keysPath - config = ConfigParser.SafeConfigParser() + config = BMConfigParser() config.read(keysPath) try: @@ -73,7 +74,7 @@ def lookupAppdataFolder(): #gets the appropriate folders for the .dat files depe def configInit(): global keysName - config = ConfigParser.SafeConfigParser() + config = BMConfigParser() config.add_section('bitmessagesettings') config.set('bitmessagesettings', 'port', '8444') #Sets the bitmessage port to stop the warning about the api not properly being setup. This is in the event that the keys.dat is in a different directory or is created locally to connect to a machine remotely. @@ -88,7 +89,7 @@ def configInit(): def apiInit(apiEnabled): global keysPath global usrPrompt - config = ConfigParser.SafeConfigParser() + config = BMConfigParser() config.read(keysPath) @@ -173,7 +174,7 @@ def apiData(): global keysPath global usrPrompt - config = ConfigParser.SafeConfigParser() + config = BMConfigParser() config.read(keysPath) #First try to load the config file (the keys.dat file) from the program directory try: @@ -183,7 +184,7 @@ def apiData(): #Could not load the keys.dat file in the program directory. Perhaps it is in the appdata directory. appDataFolder = lookupAppdataFolder() keysPath = appDataFolder + keysPath - config = ConfigParser.SafeConfigParser() + config = BMConfigParser() config.read(keysPath) try: @@ -252,7 +253,7 @@ def apiTest(): #Tests the API connection to bitmessage. Returns true if it is co def bmSettings(): #Allows the viewing and modification of keys.dat settings. global keysPath global usrPrompt - config = ConfigParser.SafeConfigParser() + config = BMConfigParser() keysPath = 'keys.dat' config.read(keysPath)#Read the keys.dat diff --git a/src/configparser.py b/src/configparser.py new file mode 100644 index 00000000..2deb3d0f --- /dev/null +++ b/src/configparser.py @@ -0,0 +1,7 @@ +from ConfigParser import SafeConfigParser + +class BMConfigParser(SafeConfigParser): + def set(self, section, option, value=None): + if value is not None: + value = value.replace('%', '%%') + return SafeConfigParser.set(self, section, option, value) diff --git a/src/shared.py b/src/shared.py index 19663472..d6d05374 100644 --- a/src/shared.py +++ b/src/shared.py @@ -11,7 +11,6 @@ useVeryEasyProofOfWorkForTesting = False # If you set this to True while on the # Libraries. import base64 import collections -import ConfigParser import os import pickle import Queue @@ -32,6 +31,7 @@ from binascii import hexlify # Project imports. from addresses import * from class_objectProcessorQueue import ObjectProcessorQueue +from configparser import BMConfigParser import highlevelcrypto import shared #import helper_startup @@ -39,7 +39,7 @@ from helper_sql import * from helper_threading import * -config = ConfigParser.SafeConfigParser() +config = BMConfigParser() myECCryptorObjects = {} MyECSubscriptionCryptorObjects = {} myAddressesByHash = {} #The key in this dictionary is the RIPE hash which is encoded in an address and value is the address itself.