New config parser class

- workaround for % in labels
- can be extended in the future
This commit is contained in:
Peter Šurda 2016-12-06 10:47:39 +01:00
parent 9f89191742
commit e647d70bbc
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
3 changed files with 17 additions and 9 deletions

View File

@ -5,7 +5,6 @@
# This is an example of a daemon client for PyBitmessage 0.4.2, by .dok (Version 0.3.0) # This is an example of a daemon client for PyBitmessage 0.4.2, by .dok (Version 0.3.0)
import ConfigParser
import xmlrpclib import xmlrpclib
import datetime import datetime
import hashlib import hashlib
@ -17,6 +16,8 @@ import time
import sys import sys
import os import os
from configparser import BMConfigParser
api = '' api = ''
keysName = 'keys.dat' keysName = 'keys.dat'
keysPath = 'keys.dat' keysPath = 'keys.dat'
@ -46,7 +47,7 @@ def restartBmNotify(): #Prompts the user to restart Bitmessage.
def safeConfigGetBoolean(section,field): def safeConfigGetBoolean(section,field):
global keysPath global keysPath
config = ConfigParser.SafeConfigParser() config = BMConfigParser()
config.read(keysPath) config.read(keysPath)
try: try:
@ -73,7 +74,7 @@ def lookupAppdataFolder(): #gets the appropriate folders for the .dat files depe
def configInit(): def configInit():
global keysName global keysName
config = ConfigParser.SafeConfigParser() config = BMConfigParser()
config.add_section('bitmessagesettings') 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. 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): def apiInit(apiEnabled):
global keysPath global keysPath
global usrPrompt global usrPrompt
config = ConfigParser.SafeConfigParser() config = BMConfigParser()
config.read(keysPath) config.read(keysPath)
@ -173,7 +174,7 @@ def apiData():
global keysPath global keysPath
global usrPrompt 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 config.read(keysPath) #First try to load the config file (the keys.dat file) from the program directory
try: 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. #Could not load the keys.dat file in the program directory. Perhaps it is in the appdata directory.
appDataFolder = lookupAppdataFolder() appDataFolder = lookupAppdataFolder()
keysPath = appDataFolder + keysPath keysPath = appDataFolder + keysPath
config = ConfigParser.SafeConfigParser() config = BMConfigParser()
config.read(keysPath) config.read(keysPath)
try: 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. def bmSettings(): #Allows the viewing and modification of keys.dat settings.
global keysPath global keysPath
global usrPrompt global usrPrompt
config = ConfigParser.SafeConfigParser() config = BMConfigParser()
keysPath = 'keys.dat' keysPath = 'keys.dat'
config.read(keysPath)#Read the keys.dat config.read(keysPath)#Read the keys.dat

7
src/configparser.py Normal file
View File

@ -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)

View File

@ -11,7 +11,6 @@ useVeryEasyProofOfWorkForTesting = False # If you set this to True while on the
# Libraries. # Libraries.
import base64 import base64
import collections import collections
import ConfigParser
import os import os
import pickle import pickle
import Queue import Queue
@ -32,6 +31,7 @@ from binascii import hexlify
# Project imports. # Project imports.
from addresses import * from addresses import *
from class_objectProcessorQueue import ObjectProcessorQueue from class_objectProcessorQueue import ObjectProcessorQueue
from configparser import BMConfigParser
import highlevelcrypto import highlevelcrypto
import shared import shared
#import helper_startup #import helper_startup
@ -39,7 +39,7 @@ from helper_sql import *
from helper_threading import * from helper_threading import *
config = ConfigParser.SafeConfigParser() config = BMConfigParser()
myECCryptorObjects = {} myECCryptorObjects = {}
MyECSubscriptionCryptorObjects = {} MyECSubscriptionCryptorObjects = {}
myAddressesByHash = {} #The key in this dictionary is the RIPE hash which is encoded in an address and value is the address itself. myAddressesByHash = {} #The key in this dictionary is the RIPE hash which is encoded in an address and value is the address itself.