Added python3 imports
This commit is contained in:
parent
6b65113bb4
commit
f811c4c4dc
26
src/api.py
26
src/api.py
|
@ -58,20 +58,30 @@ For further examples please reference `.tests.test_api`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import ConfigParser
|
|
||||||
import errno
|
import errno
|
||||||
import hashlib
|
import hashlib
|
||||||
import httplib
|
|
||||||
import json
|
import json
|
||||||
import random # nosec
|
import random # nosec
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import xmlrpclib
|
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer
|
|
||||||
from struct import pack
|
from struct import pack
|
||||||
|
|
||||||
|
try:
|
||||||
|
import httplib
|
||||||
|
except ImportError:
|
||||||
|
import http.client as httplib
|
||||||
|
try:
|
||||||
|
from xmlrpclib import Fault
|
||||||
|
except ImportError:
|
||||||
|
from xmlrpc.client import Fault
|
||||||
|
try:
|
||||||
|
from SimpleXMLRPCServer import (
|
||||||
|
SimpleXMLRPCRequestHandler, SimpleXMLRPCServer)
|
||||||
|
except ImportError:
|
||||||
|
from xmlrpc.server import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer
|
||||||
|
|
||||||
import defaults
|
import defaults
|
||||||
import helper_inbox
|
import helper_inbox
|
||||||
import helper_sent
|
import helper_sent
|
||||||
|
@ -88,7 +98,7 @@ from addresses import (
|
||||||
decodeVarint,
|
decodeVarint,
|
||||||
varintDecodeError
|
varintDecodeError
|
||||||
)
|
)
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser, NoSectionError
|
||||||
from debug import logger
|
from debug import logger
|
||||||
from helper_ackPayload import genAckPayload
|
from helper_ackPayload import genAckPayload
|
||||||
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery, sqlStoredProcedure
|
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery, sqlStoredProcedure
|
||||||
|
@ -163,7 +173,7 @@ class ErrorCodes(type):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class APIError(xmlrpclib.Fault):
|
class APIError(Fault):
|
||||||
"""
|
"""
|
||||||
APIError exception class
|
APIError exception class
|
||||||
|
|
||||||
|
@ -843,7 +853,7 @@ class BMRPCDispatcher(object):
|
||||||
' Use deleteAddress API call instead.')
|
' Use deleteAddress API call instead.')
|
||||||
try:
|
try:
|
||||||
self.config.remove_section(address)
|
self.config.remove_section(address)
|
||||||
except ConfigParser.NoSectionError:
|
except NoSectionError:
|
||||||
raise APIError(
|
raise APIError(
|
||||||
13, 'Could not find this address in your keys.dat file.')
|
13, 'Could not find this address in your keys.dat file.')
|
||||||
self.config.save()
|
self.config.save()
|
||||||
|
@ -860,7 +870,7 @@ class BMRPCDispatcher(object):
|
||||||
address = addBMIfNotPresent(address)
|
address = addBMIfNotPresent(address)
|
||||||
try:
|
try:
|
||||||
self.config.remove_section(address)
|
self.config.remove_section(address)
|
||||||
except ConfigParser.NoSectionError:
|
except NoSectionError:
|
||||||
raise APIError(
|
raise APIError(
|
||||||
13, 'Could not find this address in your keys.dat file.')
|
13, 'Could not find this address in your keys.dat file.')
|
||||||
self.config.save()
|
self.config.save()
|
||||||
|
|
|
@ -2,10 +2,17 @@
|
||||||
BMConfigParser class definition and default configuration settings
|
BMConfigParser class definition and default configuration settings
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import ConfigParser
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
try:
|
||||||
|
from ConfigParser import (
|
||||||
|
ConfigParser, InterpolationError, NoOptionError, NoSectionError,
|
||||||
|
SafeConfigParser)
|
||||||
|
except ImportError:
|
||||||
|
from configparser import (
|
||||||
|
ConfigParser, InterpolationError, NoOptionError, NoSectionError)
|
||||||
|
SafeConfigParser = ConfigParser
|
||||||
|
|
||||||
import state
|
import state
|
||||||
from singleton import Singleton
|
from singleton import Singleton
|
||||||
|
@ -42,7 +49,7 @@ BMConfigDefaults = {
|
||||||
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class BMConfigParser(ConfigParser.SafeConfigParser):
|
class BMConfigParser(SafeConfigParser):
|
||||||
"""
|
"""
|
||||||
Singleton class inherited from :class:`ConfigParser.SafeConfigParser`
|
Singleton class inherited from :class:`ConfigParser.SafeConfigParser`
|
||||||
with additional methods specific to bitmessage config.
|
with additional methods specific to bitmessage config.
|
||||||
|
@ -57,24 +64,24 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
|
||||||
raise TypeError("option values must be strings")
|
raise TypeError("option values must be strings")
|
||||||
if not self.validate(section, option, value):
|
if not self.validate(section, option, value):
|
||||||
raise ValueError("Invalid value %s" % value)
|
raise ValueError("Invalid value %s" % value)
|
||||||
return ConfigParser.ConfigParser.set(self, section, option, value)
|
return ConfigParser.set(self, section, option, value)
|
||||||
|
|
||||||
def get(self, section, option, raw=False, variables=None):
|
def get(self, section, option, raw=False, variables=None):
|
||||||
# pylint: disable=arguments-differ
|
# pylint: disable=arguments-differ
|
||||||
try:
|
try:
|
||||||
if section == "bitmessagesettings" and option == "timeformat":
|
if section == "bitmessagesettings" and option == "timeformat":
|
||||||
return ConfigParser.ConfigParser.get(
|
return ConfigParser.get(
|
||||||
self, section, option, raw, variables)
|
self, section, option, raw, variables)
|
||||||
try:
|
try:
|
||||||
return self._temp[section][option]
|
return self._temp[section][option]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
return ConfigParser.ConfigParser.get(
|
return ConfigParser.get(
|
||||||
self, section, option, True, variables)
|
self, section, option, True, variables)
|
||||||
except ConfigParser.InterpolationError:
|
except InterpolationError:
|
||||||
return ConfigParser.ConfigParser.get(
|
return ConfigParser.get(
|
||||||
self, section, option, True, variables)
|
self, section, option, True, variables)
|
||||||
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e:
|
except (NoSectionError, NoOptionError) as e:
|
||||||
try:
|
try:
|
||||||
return BMConfigDefaults[section][option]
|
return BMConfigDefaults[section][option]
|
||||||
except (KeyError, ValueError, AttributeError):
|
except (KeyError, ValueError, AttributeError):
|
||||||
|
@ -91,8 +98,7 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
|
||||||
"""Return value as boolean, False on exceptions"""
|
"""Return value as boolean, False on exceptions"""
|
||||||
try:
|
try:
|
||||||
return self.getboolean(section, field)
|
return self.getboolean(section, field)
|
||||||
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
|
except (NoSectionError, NoOptionError, ValueError, AttributeError):
|
||||||
ValueError, AttributeError):
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def safeGetInt(self, section, field, default=0):
|
def safeGetInt(self, section, field, default=0):
|
||||||
|
@ -100,23 +106,21 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
|
||||||
0 if default missing"""
|
0 if default missing"""
|
||||||
try:
|
try:
|
||||||
return self.getint(section, field)
|
return self.getint(section, field)
|
||||||
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
|
except (NoSectionError, NoOptionError, ValueError, AttributeError):
|
||||||
ValueError, AttributeError):
|
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def safeGet(self, section, option, default=None):
|
def safeGet(self, section, option, default=None):
|
||||||
"""Return value as is, default on exceptions, None if default missing"""
|
"""Return value as is, default on exceptions, None if default missing"""
|
||||||
try:
|
try:
|
||||||
return self.get(section, option)
|
return self.get(section, option)
|
||||||
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
|
except (NoSectionError, NoOptionError, ValueError, AttributeError):
|
||||||
ValueError, AttributeError):
|
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def items(self, section, raw=False, variables=None):
|
def items(self, section, raw=False, variables=None):
|
||||||
"""Return section variables as parent,
|
"""Return section variables as parent,
|
||||||
but override the "raw" argument to always True"""
|
but override the "raw" argument to always True"""
|
||||||
# pylint: disable=arguments-differ
|
# pylint: disable=arguments-differ
|
||||||
return ConfigParser.ConfigParser.items(self, section, True, variables)
|
return ConfigParser.items(self, section, True, variables)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def addresses():
|
def addresses():
|
||||||
|
@ -125,21 +129,21 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
|
||||||
x for x in BMConfigParser().sections() if x.startswith('BM-')]
|
x for x in BMConfigParser().sections() if x.startswith('BM-')]
|
||||||
|
|
||||||
def read(self, filenames):
|
def read(self, filenames):
|
||||||
ConfigParser.ConfigParser.read(self, filenames)
|
ConfigParser.read(self, filenames)
|
||||||
for section in self.sections():
|
for section in self.sections():
|
||||||
for option in self.options(section):
|
for option in self.options(section):
|
||||||
try:
|
try:
|
||||||
if not self.validate(
|
if not self.validate(
|
||||||
section, option,
|
section, option,
|
||||||
ConfigParser.ConfigParser.get(self, section, option)
|
ConfigParser.get(self, section, option)
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
newVal = BMConfigDefaults[section][option]
|
newVal = BMConfigDefaults[section][option]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
continue
|
continue
|
||||||
ConfigParser.ConfigParser.set(
|
ConfigParser.set(
|
||||||
self, section, option, newVal)
|
self, section, option, newVal)
|
||||||
except ConfigParser.InterpolationError:
|
except InterpolationError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
|
|
@ -35,7 +35,6 @@ Logging is thread-safe so you don't have to worry about locks,
|
||||||
just import and log.
|
just import and log.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import ConfigParser
|
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import os
|
import os
|
||||||
|
@ -43,6 +42,7 @@ import sys
|
||||||
|
|
||||||
import helper_startup
|
import helper_startup
|
||||||
import state
|
import state
|
||||||
|
from bmconfigparser import NoSectionError
|
||||||
|
|
||||||
helper_startup.loadConfig()
|
helper_startup.loadConfig()
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ def configureLogging():
|
||||||
False,
|
False,
|
||||||
'Loaded logger configuration from %s' % logging_config
|
'Loaded logger configuration from %s' % logging_config
|
||||||
)
|
)
|
||||||
except (OSError, ConfigParser.NoSectionError):
|
except (OSError, NoSectionError):
|
||||||
if os.path.isfile(logging_config):
|
if os.path.isfile(logging_config):
|
||||||
fail_msg = \
|
fail_msg = \
|
||||||
'Failed to load logger configuration from %s, using default' \
|
'Failed to load logger configuration from %s, using default' \
|
||||||
|
|
Reference in New Issue
Block a user