summaryrefslogtreecommitdiffstats
path: root/Lib/xmlrpc
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2022-01-25 17:58:13 (GMT)
committerGitHub <noreply@github.com>2022-01-25 17:58:13 (GMT)
commitd69d3d8b2fec501e51309221fb1fa4622c8a3db3 (patch)
treed17e94fe5a27b1c90a3eea30e3e902da691a8d7b /Lib/xmlrpc
parent45f5f52601ebccb195c19cb0a77beaf7f7dfa56a (diff)
downloadcpython-d69d3d8b2fec501e51309221fb1fa4622c8a3db3.zip
cpython-d69d3d8b2fec501e51309221fb1fa4622c8a3db3.tar.gz
cpython-d69d3d8b2fec501e51309221fb1fa4622c8a3db3.tar.bz2
bpo-46510: simplify exception handling code in xmlrpc (GH-30878)
Diffstat (limited to 'Lib/xmlrpc')
-rw-r--r--Lib/xmlrpc/server.py46
1 files changed, 15 insertions, 31 deletions
diff --git a/Lib/xmlrpc/server.py b/Lib/xmlrpc/server.py
index e22e480..4228a85 100644
--- a/Lib/xmlrpc/server.py
+++ b/Lib/xmlrpc/server.py
@@ -268,17 +268,11 @@ class SimpleXMLRPCDispatcher:
except Fault as fault:
response = dumps(fault, allow_none=self.allow_none,
encoding=self.encoding)
- except:
- # report exception back to server
- exc_type, exc_value, exc_tb = sys.exc_info()
- try:
- response = dumps(
- Fault(1, "%s:%s" % (exc_type, exc_value)),
- encoding=self.encoding, allow_none=self.allow_none,
- )
- finally:
- # Break reference cycle
- exc_type = exc_value = exc_tb = None
+ except BaseException as exc:
+ response = dumps(
+ Fault(1, "%s:%s" % (type(exc), exc)),
+ encoding=self.encoding, allow_none=self.allow_none,
+ )
return response.encode(self.encoding, 'xmlcharrefreplace')
@@ -368,16 +362,11 @@ class SimpleXMLRPCDispatcher:
{'faultCode' : fault.faultCode,
'faultString' : fault.faultString}
)
- except:
- exc_type, exc_value, exc_tb = sys.exc_info()
- try:
- results.append(
- {'faultCode' : 1,
- 'faultString' : "%s:%s" % (exc_type, exc_value)}
- )
- finally:
- # Break reference cycle
- exc_type = exc_value = exc_tb = None
+ except BaseException as exc:
+ results.append(
+ {'faultCode' : 1,
+ 'faultString' : "%s:%s" % (type(exc), exc)}
+ )
return results
def _dispatch(self, method, params):
@@ -634,19 +623,14 @@ class MultiPathXMLRPCServer(SimpleXMLRPCServer):
try:
response = self.dispatchers[path]._marshaled_dispatch(
data, dispatch_method, path)
- except:
+ except BaseException as exc:
# report low level exception back to server
# (each dispatcher should have handled their own
# exceptions)
- exc_type, exc_value = sys.exc_info()[:2]
- try:
- response = dumps(
- Fault(1, "%s:%s" % (exc_type, exc_value)),
- encoding=self.encoding, allow_none=self.allow_none)
- response = response.encode(self.encoding, 'xmlcharrefreplace')
- finally:
- # Break reference cycle
- exc_type = exc_value = None
+ response = dumps(
+ Fault(1, "%s:%s" % (type(exc), exc)),
+ encoding=self.encoding, allow_none=self.allow_none)
+ response = response.encode(self.encoding, 'xmlcharrefreplace')
return response
class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher):