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