Skip to content

Commit c11d80a

Browse files
committed
Do not use bare except lint
1 parent 351fe5c commit c11d80a

File tree

6 files changed

+18
-27
lines changed

6 files changed

+18
-27
lines changed

channelfinder/ChannelFinderClient.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,15 @@ def __init__(self, BaseURL=None, username=None, password=None):
4040
:param username: user name authorized by channel finder service
4141
:param password: password for the authorized user
4242
"""
43-
try:
44-
self.__baseURL = self.__getDefaultConfig("BaseURL", BaseURL)
45-
self.__userName = self.__getDefaultConfig("username", username)
46-
self.__password = self.__getDefaultConfig("password", password)
47-
if self.__userName and self.__password:
48-
self.__auth = auth.HTTPBasicAuth(self.__userName, self.__password)
49-
else:
50-
self.__auth = None
51-
self.__session = requests.Session()
52-
self.__session.mount(self.__baseURL, HTTPAdapter())
53-
except:
54-
raise RuntimeError("Failed to create client to " + self.__baseURL)
43+
self.__baseURL = self.__getDefaultConfig("BaseURL", BaseURL)
44+
self.__userName = self.__getDefaultConfig("username", username)
45+
self.__password = self.__getDefaultConfig("password", password)
46+
if self.__userName and self.__password:
47+
self.__auth = auth.HTTPBasicAuth(self.__userName, self.__password)
48+
else:
49+
self.__auth = None
50+
self.__session = requests.Session()
51+
self.__session.mount(self.__baseURL, HTTPAdapter())
5552

5653
def __getDefaultConfig(self, key, ref):
5754
"""

channelfinder/cfMonitorTest.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ def mainRun(opts, args):
8686

8787

8888
def check(pvNames, hostName, iocName):
89-
try:
90-
client = ChannelFinderClient()
91-
except:
92-
raise RuntimeError("Unable to create a valid webResourceClient")
89+
client = ChannelFinderClient()
9390
channels = client.find(property=[("hostName", hostName), ("iocName", iocName)])
9491
if channels and len(pvNames) == len(channels):
9592
for channel in channels:

channelfinder/cfPropertyManager/CFPropertyManager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
from __future__ import print_function
8+
from configparser import NoSectionError
89
import re
910
from optparse import OptionParser
1011
from getpass import getpass
@@ -159,7 +160,7 @@ def __getDefaultConfig(arg, value):
159160
if value is None:
160161
try:
161162
return basecfg.get("DEFAULT", arg)
162-
except:
163+
except (KeyError, NoSectionError):
163164
return None
164165
else:
165166
return value
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .CFPropertyManager import CFPropertyManager
22

3-
__all__ = ["CFPropertyManager"]
3+
__all__ = ["CFPropertyManager"]

channelfinder/cfUpdate/CFUpdateIOC.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from __future__ import print_function
1414

15+
from configparser import NoSectionError
1516
import os
1617
import re
1718
from optparse import OptionParser
@@ -79,12 +80,7 @@ def updateChannelFinder(
7980
if hostName is None or iocName is None:
8081
raise RuntimeError("missing hostName or iocName")
8182
channels = []
82-
try:
83-
client = ChannelFinderClient(
84-
BaseURL=service, username=username, password=password
85-
)
86-
except:
87-
raise RuntimeError("Unable to create a valid webResourceClient")
83+
client = ChannelFinderClient(BaseURL=service, username=username, password=password)
8884
checkPropertiesExist(client, owner)
8985
previousChannelsList = client.findByArgs(
9086
[("hostName", hostName), ("iocName", iocName)]
@@ -279,7 +275,7 @@ def __getDefaultConfig(arg, value):
279275
if value is None:
280276
try:
281277
return basecfg.get("DEFAULT", arg)
282-
except:
278+
except (KeyError, NoSectionError):
283279
return None
284280
else:
285281
return value

test/testChannelFinderClient.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def testCreateAndDeleteTagWithChannel(self):
150150
"channels": [self.testChannels[0]],
151151
}
152152
try:
153-
result = self.clientTag.set(tag=testTag)
153+
_ = self.clientTag.set(tag=testTag)
154154
foundtag = self.client.findTag(testTag["name"])
155155
self.assertIsNotNone(foundtag, "failed to create a test tag")
156156
self.assertTrue(
@@ -410,7 +410,7 @@ def testCreateAndDeleteProperty(self):
410410
"""
411411
testProperty = {"name": "setTestProp", "owner": self.propOwner}
412412
try:
413-
result = self.clientProp.set(property=testProperty)
413+
_ = self.clientProp.set(property=testProperty)
414414
foundProperty = self.client.findProperty(testProperty["name"])
415415
self.assertIsNotNone(foundProperty, "failed to create a test property")
416416
self.assertTrue(

0 commit comments

Comments
 (0)