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 committed Sep 11, 2024
1 parent 0539eb6 commit 4a385f8
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

Check warning on line 29 in bin/receiver.py

View check run for this annotation

Codecov / codecov/patch

bin/receiver.py#L29

Added line #L29 was not covered by tests


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'})

Check warning on line 62 in bin/receiver.py

View check run for this annotation

Codecov / codecov/patch

bin/receiver.py#L62

Added line #L62 was not covered by tests
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

Check warning on line 29 in bin/sender.py

View check run for this annotation

Codecov / codecov/patch

bin/sender.py#L29

Added line #L29 was not covered by tests


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'})

Check warning on line 54 in bin/sender.py

View check run for this annotation

Codecov / codecov/patch

bin/sender.py#L54

Added line #L54 was not covered by tests
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:

Check warning on line 61 in ssm/agents.py

View check run for this annotation

Codecov / codecov/patch

ssm/agents.py#L61

Added line #L61 was not covered by tests
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')

Check warning on line 75 in ssm/agents.py

View check run for this annotation

Codecov / codecov/patch

ssm/agents.py#L75

Added line #L75 was not covered by tests

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:

Check warning on line 106 in ssm/agents.py

View check run for this annotation

Codecov / codecov/patch

ssm/agents.py#L106

Added line #L106 was not covered by tests
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:

Check warning on line 124 in ssm/agents.py

View check run for this annotation

Codecov / codecov/patch

ssm/agents.py#L124

Added line #L124 was not covered by tests
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:

Check warning on line 136 in ssm/agents.py

View check run for this annotation

Codecov / codecov/patch

ssm/agents.py#L136

Added line #L136 was not covered by tests
# 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:

Check warning on line 146 in ssm/agents.py

View check run for this annotation

Codecov / codecov/patch

ssm/agents.py#L146

Added line #L146 was not covered by tests
# 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:

Check warning on line 173 in ssm/agents.py

View check run for this annotation

Codecov / codecov/patch

ssm/agents.py#L173

Added line #L173 was not covered by tests
# If option not set, resort to value of verify_server_cert set above.
pass
except ConfigParser.NoOptionError:
except configparser.NoOptionError:

Check warning on line 176 in ssm/agents.py

View check run for this annotation

Codecov / codecov/patch

ssm/agents.py#L176

Added line #L176 was not covered by tests
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:

Check warning on line 183 in ssm/agents.py

View check run for this annotation

Codecov / codecov/patch

ssm/agents.py#L183

Added line #L183 was not covered by tests
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:

Check warning on line 190 in ssm/agents.py

View check run for this annotation

Codecov / codecov/patch

ssm/agents.py#L190

Added line #L190 was not covered by tests
log.info('No path type defined, assuming dirq.')
path_type = 'dirq'

Expand Down

0 comments on commit 4a385f8

Please sign in to comment.