Skip to content

Commit

Permalink
Removed except ImportError for configparser
Browse files Browse the repository at this point in the history
replased upper case ConfigParser for python 2 with the lower case python 3 version configparser
  • Loading branch information
Will-Cross1 authored and tofu-rocketry committed Sep 11, 2024
1 parent 64d017a commit 213f283
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
7 changes: 2 additions & 5 deletions bin/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
import sys
from optparse import OptionParser

try:
import ConfigParser
except ImportError:
import configparser as ConfigParser
import configparser


def main():
Expand Down Expand Up @@ -62,7 +59,7 @@ def main():

# Check if config file exists using os.path.isfile function.
if os.path.isfile(options.config):
cp = ConfigParser.ConfigParser({'use_ssl': 'true'})
cp = configparser.ConfigParser({'use_ssl': 'true'})
cp.read(options.config)
else:
print("Config file not found at", options.config)
Expand Down
7 changes: 2 additions & 5 deletions bin/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
import os
import sys

try:
import ConfigParser
except ImportError:
import configparser as ConfigParser
import configparser


def main():
Expand All @@ -54,7 +51,7 @@ def main():

# Check if config file exists using os.path.isfile function.
if os.path.isfile(options.config):
cp = ConfigParser.ConfigParser({'use_ssl': 'true'})
cp = configparser.ConfigParser({'use_ssl': 'true'})
cp.read(options.config)
else:
print("Config file not found at", options.config)
Expand Down
27 changes: 12 additions & 15 deletions ssm/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
import sys
import time

try:
import ConfigParser
except ImportError:
import configparser as ConfigParser
import configparser

try:
from daemon import DaemonContext
Expand Down Expand Up @@ -61,7 +58,7 @@ def logging_helper(cp):
cp.get('logging', 'level'),
cp.getboolean('logging', 'console')
)
except (ConfigParser.Error, ValueError, IOError) as err:
except (configparser.Error, ValueError, IOError) as err:
print('Error configuring logging: %s' % err)
print('The system will exit.')
sys.exit(1)
Expand All @@ -75,12 +72,12 @@ def get_protocol(cp, log):
elif 'receiver' in cp.sections():
protocol = cp.get('receiver', 'protocol')
else:
raise ConfigParser.NoSectionError('sender or receiver')
raise configparser.NoSectionError('sender or receiver')

if protocol not in (Ssm2.STOMP_MESSAGING, Ssm2.AMS_MESSAGING):
raise ValueError

except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
except (configparser.NoSectionError, configparser.NoOptionError):
# If the newer configuration setting 'protocol' is not set, use 'STOMP'
# for backwards compatability.
protocol = Ssm2.STOMP_MESSAGING
Expand All @@ -106,7 +103,7 @@ def get_ssm_args(protocol, cp, log):
host = cp.get('broker', 'host')
port = cp.get('broker', 'port')
brokers = [(host, int(port))]
except ConfigParser.NoOptionError:
except configparser.NoOptionError:
log.error('Host options incorrectly supplied for message broker '
'or AMS endpoint. Please check configuration.')
log.error('System will exit.')
Expand All @@ -124,7 +121,7 @@ def get_ssm_args(protocol, cp, log):
# the exact destination type.
brokers = [host]

except ConfigParser.NoOptionError:
except configparser.NoOptionError:
log.error('The host must be specified when connecting to AMS, '
'please check your configuration')
log.error('System will exit.')
Expand All @@ -136,7 +133,7 @@ def get_ssm_args(protocol, cp, log):
try:
project = cp.get('messaging', 'ams_project')

except (ConfigParser.Error, ValueError, IOError) as err:
except (configparser.Error, ValueError, IOError) as err:
# A project is needed to successfully send to an
# AMS instance, so log and then exit on an error.
log.error('Error configuring AMS values: %s', err)
Expand All @@ -146,7 +143,7 @@ def get_ssm_args(protocol, cp, log):

try:
token = cp.get('messaging', 'token')
except (ConfigParser.Error, ValueError, IOError) as err:
except (configparser.Error, ValueError, IOError) as err:
# A token is not necessarily needed, if the cert and key can be
# used by the underlying auth system to get a suitable token.
log.info('No AMS token provided, using cert/key pair instead.')
Expand All @@ -173,24 +170,24 @@ def run_sender(protocol, brokers, project, token, cp, log):
log.info('Messages will be encrypted using %s', server_dn)
try:
verify_server_cert = cp.getboolean('certificates', 'verify_server_cert')
except ConfigParser.NoOptionError:
except configparser.NoOptionError:
# If option not set, resort to value of verify_server_cert set above.
pass
except ConfigParser.NoOptionError:
except configparser.NoOptionError:
log.info('No server certificate supplied. Will not encrypt messages.')

try:
destination = cp.get('messaging', 'destination')
if destination == '':
raise Ssm2Exception('No destination queue is configured.')
except ConfigParser.NoOptionError as e:
except configparser.NoOptionError as e:
raise Ssm2Exception(e)

# Determine what type of message store we are interacting with,
# i.e. a dirq QueueSimple object or a plain MessageDirectory directory.
try:
path_type = cp.get('messaging', 'path_type')
except ConfigParser.NoOptionError:
except configparser.NoOptionError:
log.info('No path type defined, assuming dirq.')
path_type = 'dirq'

Expand Down

0 comments on commit 213f283

Please sign in to comment.