Old exception handling format to new one

This commit is contained in:
Miroslav Stampar
2019-01-22 14:09:13 +01:00
parent ba356baab0
commit bdc4457f34
11 changed files with 26 additions and 27 deletions

View File

@@ -1836,7 +1836,7 @@ class UnicodeDammit:
u = self._toUnicode(markup, proposed)
self.markup = u
self.originalEncoding = proposed
except Exception, e:
except Exception as e:
# print "That didn't work!"
# print e
return None

View File

@@ -1100,7 +1100,7 @@ def _ParseFileEx(file, base_uri,
data = file.read(CHUNK)
try:
fp.feed(data)
except ParseError, e:
except ParseError as e:
e.base_uri = base_uri
raise
if len(data) != CHUNK: break
@@ -2902,7 +2902,7 @@ class HTMLForm:
control = self.find_control(name)
try:
control.value = value
except AttributeError, e:
except AttributeError as e:
raise ValueError(str(e))
def get_value(self,

View File

@@ -180,7 +180,7 @@ class AnsiToWin32(object):
def _write(self, text, retry=5):
try:
self.wrapped.write(text)
except IOError, err:
except IOError as err:
if not (err.errno == 0 and retry > 0):
raise
self._write(text, retry-1)

View File

@@ -695,7 +695,7 @@ class XmlTokenizer:
self.final = len(data) < size
try:
self.parser.Parse(data, self.final)
except xml.parsers.expat.ExpatError, e:
except xml.parsers.expat.ExpatError as e:
#if e.code == xml.parsers.expat.errors.XML_ERROR_NO_ELEMENTS:
if e.code == 3:
pass

View File

@@ -238,7 +238,7 @@ class KeepAliveHandler:
self._cm.add(host, h, 0)
self._start_transaction(h, req)
r = h.getresponse()
except (socket.error, httplib.HTTPException), err:
except (socket.error, httplib.HTTPException) as err:
raise urllib2.URLError(err)
if DEBUG: DEBUG.info("STATUS: %s, %s", r.status, r.reason)
@@ -323,7 +323,7 @@ class KeepAliveHandler:
h.putrequest(req.get_method() or 'GET', req.selector, skip_host=req.has_header("Host"), skip_accept_encoding=req.has_header("Accept-encoding"))
else:
h.putrequest(req.get_method() or 'GET', req.get_selector(), skip_host=req.has_header("Host"), skip_accept_encoding=req.has_header("Accept-encoding"))
except (socket.error, httplib.HTTPException), err:
except (socket.error, httplib.HTTPException) as err:
raise urllib2.URLError(err)
if not req.headers.has_key('Connection'):
@@ -495,7 +495,7 @@ def error_handler(url):
fo.close()
try: status, reason = fo.status, fo.reason
except AttributeError: status, reason = None, None
except IOError, e:
except IOError as e:
print " EXCEPTION: %s" % e
raise
else:
@@ -613,7 +613,7 @@ def test_timeout(url):
def test(url, N=10):
print "checking error hander (do this on a non-200)"
try: error_handler(url)
except IOError, e:
except IOError as e:
print "exiting - exception will prevent further tests"
sys.exit()
print