forked from upstream/UXP-mirror
Issue #2974 - Part 8: Adapt except
2to3 . --fix except -wpn Python 3 exception syntax is different. Comma-based syntax is gone, much like print syntax is changed. This lets you have the old behavior. Mechanical. Ref: PEP 3110 https://peps.python.org/pep-3110/
This commit is contained in:
1 parent
4906a75883
commit
46f126c10c
113 files changed
+321
-314
No files matched your search
@@ -206,22 +206,22 @@ def test_nice_formatting_errors():
|
||||
t = TestTerminal()
|
||||
try:
|
||||
t.bold_misspelled('hey')
|
||||
except TypeError, e:
|
||||
except TypeError as e:
|
||||
assert 'probably misspelled' in e.args[0]
|
||||
|
||||
try:
|
||||
t.bold_misspelled(u'hey') # unicode
|
||||
except TypeError, e:
|
||||
except TypeError as e:
|
||||
assert 'probably misspelled' in e.args[0]
|
||||
|
||||
try:
|
||||
t.bold_misspelled(None) # an arbitrary non-string
|
||||
except TypeError, e:
|
||||
except TypeError as e:
|
||||
assert 'probably misspelled' not in e.args[0]
|
||||
|
||||
try:
|
||||
t.bold_misspelled('a', 'b') # >1 string arg
|
||||
except TypeError, e:
|
||||
except TypeError as e:
|
||||
assert 'probably misspelled' not in e.args[0]
|
||||
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ class PropertiesChecker(Checker):
|
||||
def checkPrintf(self, refSpecs, l10nValue):
|
||||
try:
|
||||
l10nSpecs = self.getPrintfSpecs(l10nValue)
|
||||
except PrintfException, e:
|
||||
except PrintfException as e:
|
||||
yield ('error', e.pos, e.msg, 'printf')
|
||||
return
|
||||
if refSpecs != l10nSpecs:
|
||||
@@ -253,7 +253,7 @@ class DTDChecker(Checker):
|
||||
parser.parse(StringIO(self.tmpl %
|
||||
(refEnt.all.encode('utf-8') + entities,
|
||||
'&%s;' % refEnt.key.encode('utf-8'))))
|
||||
except sax.SAXParseException, e:
|
||||
except sax.SAXParseException as e:
|
||||
yield ('warning',
|
||||
(0, 0),
|
||||
"can't parse en-US value", 'xmlparse')
|
||||
@@ -275,7 +275,7 @@ class DTDChecker(Checker):
|
||||
parser.parse(StringIO(self.tmpl % (
|
||||
l10nEnt.all.encode('utf-8') + _entities,
|
||||
'&%s;' % l10nEnt.key.encode('utf-8'))))
|
||||
except sax.SAXParseException, e:
|
||||
except sax.SAXParseException as e:
|
||||
# xml parse error, yield error
|
||||
# sometimes, the error is reported on our fake closing
|
||||
# element, make that the end of the last line
|
||||
|
||||
@@ -109,7 +109,7 @@ Be careful to specify the right merge directory when using this option."""),
|
||||
try:
|
||||
observer = compareApp(app, merge_stage=options.merge,
|
||||
clobber=options.clobber)
|
||||
except (OSError, IOError), exc:
|
||||
except (OSError, IOError) as exc:
|
||||
print("FAIL: " + str(exc))
|
||||
self.parser.exit(2)
|
||||
return observer
|
||||
|
||||
@@ -448,7 +448,7 @@ class ContentComparer:
|
||||
# we didn't parse this before
|
||||
try:
|
||||
p.readContents(ref_file.getContents())
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.notify('error', ref_file, str(e))
|
||||
return
|
||||
self.reference[ref_file] = p.parse()
|
||||
@@ -458,7 +458,7 @@ class ContentComparer:
|
||||
try:
|
||||
p.readContents(l10n.getContents())
|
||||
l10n_entities, l10n_map = p.parse()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.notify('error', l10n, str(e))
|
||||
return
|
||||
lines = []
|
||||
@@ -573,7 +573,7 @@ class ContentComparer:
|
||||
try:
|
||||
p.readContents(f.getContents())
|
||||
entities, map = p.parse()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.notify('error', f, str(e))
|
||||
return
|
||||
self.notify('missingInFiles', missing, len(map))
|
||||
|
||||
@@ -122,7 +122,7 @@ class Parser:
|
||||
f = codecs.open(file, 'r', self.encoding)
|
||||
try:
|
||||
self.contents = f.read()
|
||||
except UnicodeDecodeError, e:
|
||||
except UnicodeDecodeError as e:
|
||||
(logging.getLogger('locales')
|
||||
.error("Can't read file: " + file + '; ' + str(e)))
|
||||
self.contents = u''
|
||||
|
||||
@@ -80,7 +80,7 @@ class Manifest(object):
|
||||
def load_and_parse(self):
|
||||
try:
|
||||
manifest = json.load(open(self.file.fullpath))
|
||||
except (ValueError, IOError), e:
|
||||
except (ValueError, IOError) as e:
|
||||
if self.watcher:
|
||||
self.watcher.notify('error', self.file, str(e))
|
||||
return False
|
||||
|
||||
@@ -1641,7 +1641,7 @@ class ConfigObj(Section):
|
||||
comment = ''
|
||||
try:
|
||||
value = unrepr(value)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
if type(e) == UnknownType:
|
||||
msg = 'Unknown name or type in value at line %s.'
|
||||
else:
|
||||
@@ -1654,7 +1654,7 @@ class ConfigObj(Section):
|
||||
comment = ''
|
||||
try:
|
||||
value = unrepr(value)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
if isinstance(e, UnknownType):
|
||||
msg = 'Unknown name or type in value at line %s.'
|
||||
else:
|
||||
@@ -1929,11 +1929,11 @@ class ConfigObj(Section):
|
||||
raise_errors=True,
|
||||
file_error=True,
|
||||
_inspec=True)
|
||||
except ConfigObjError, e:
|
||||
except ConfigObjError as e:
|
||||
# FIXME: Should these errors have a reference
|
||||
# to the already parsed ConfigObj ?
|
||||
raise ConfigspecError('Parsing configspec failed: %s' % e)
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
raise IOError('Reading configspec failed: %s' % e)
|
||||
|
||||
self.configspec = configspec
|
||||
@@ -2189,7 +2189,7 @@ class ConfigObj(Section):
|
||||
val,
|
||||
missing=missing
|
||||
)
|
||||
except validator.baseErrorClass, e:
|
||||
except validator.baseErrorClass as e:
|
||||
if not preserve_errors or isinstance(e, self._vdtMissingValue):
|
||||
out[entry] = False
|
||||
else:
|
||||
|
||||
@@ -739,7 +739,7 @@ def _is_num_param(names, values, to_float=False):
|
||||
elif isinstance(val, (int, long, float, basestring)):
|
||||
try:
|
||||
out_params.append(fun(val))
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
raise VdtParamError(name, val)
|
||||
else:
|
||||
raise VdtParamError(name, val)
|
||||
@@ -1292,7 +1292,7 @@ def is_mixed_list(value, *args):
|
||||
raise VdtValueTooLongError(value)
|
||||
try:
|
||||
return [fun_dict[arg](val) for arg, val in zip(args, value)]
|
||||
except KeyError, e:
|
||||
except KeyError as e:
|
||||
raise VdtParamError('mixed_list', e)
|
||||
|
||||
|
||||
|
||||
@@ -212,7 +212,7 @@ class Doctor(object):
|
||||
fsutil_output = subprocess.check_output(command)
|
||||
status = 'GOOD, FIXED'
|
||||
desc = 'lastaccess disabled systemwide'
|
||||
except subprocess.CalledProcessError, e:
|
||||
except subprocess.CalledProcessError as e:
|
||||
desc = 'lastaccess enabled systemwide'
|
||||
if e.output.find('denied') != -1:
|
||||
status = 'BAD, FIX DENIED'
|
||||
|
||||
@@ -372,7 +372,7 @@ class JarMaker(object):
|
||||
jarfilepath = jarfile + '.jar'
|
||||
try:
|
||||
os.makedirs(os.path.dirname(jarfilepath))
|
||||
except OSError, error:
|
||||
except OSError as error:
|
||||
if error.errno != errno.EEXIST:
|
||||
raise
|
||||
jf = ZipFile(jarfilepath, 'a', lock=True)
|
||||
@@ -514,7 +514,7 @@ class JarMaker(object):
|
||||
# remove previous link or file
|
||||
try:
|
||||
os.remove(out)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
return open(out, 'wb')
|
||||
@@ -525,7 +525,7 @@ class JarMaker(object):
|
||||
if not os.path.isdir(outdir):
|
||||
try:
|
||||
os.makedirs(outdir)
|
||||
except OSError, error:
|
||||
except OSError as error:
|
||||
if error.errno != errno.EEXIST:
|
||||
raise
|
||||
return out
|
||||
@@ -541,7 +541,7 @@ class JarMaker(object):
|
||||
# remove previous link or file
|
||||
try:
|
||||
os.remove(out)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
if sys.platform != 'win32':
|
||||
|
||||
@@ -152,7 +152,7 @@ def ensureParentDir(path):
|
||||
if d and not os.path.exists(path):
|
||||
try:
|
||||
os.makedirs(d)
|
||||
except OSError, error:
|
||||
except OSError as error:
|
||||
if error.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ class BaseConstructor(object):
|
||||
key = self.construct_object(key_node, deep=deep)
|
||||
try:
|
||||
hash(key)
|
||||
except TypeError, exc:
|
||||
except TypeError as exc:
|
||||
raise ConstructorError("while constructing a mapping", node.start_mark,
|
||||
"found unacceptable key (%s)" % exc, key_node.start_mark)
|
||||
value = self.construct_object(value_node, deep=deep)
|
||||
@@ -285,7 +285,7 @@ class SafeConstructor(BaseConstructor):
|
||||
value = self.construct_scalar(node)
|
||||
try:
|
||||
return str(value).decode('base64')
|
||||
except (binascii.Error, UnicodeEncodeError), exc:
|
||||
except (binascii.Error, UnicodeEncodeError) as exc:
|
||||
raise ConstructorError(None, None,
|
||||
"failed to decode base64 data: %s" % exc, node.start_mark)
|
||||
|
||||
@@ -487,7 +487,7 @@ class Constructor(SafeConstructor):
|
||||
"expected non-empty name appended to the tag", mark)
|
||||
try:
|
||||
__import__(name)
|
||||
except ImportError, exc:
|
||||
except ImportError as exc:
|
||||
raise ConstructorError("while constructing a Python module", mark,
|
||||
"cannot find module %r (%s)" % (name.encode('utf-8'), exc), mark)
|
||||
return sys.modules[name]
|
||||
@@ -503,7 +503,7 @@ class Constructor(SafeConstructor):
|
||||
object_name = name
|
||||
try:
|
||||
__import__(module_name)
|
||||
except ImportError, exc:
|
||||
except ImportError as exc:
|
||||
raise ConstructorError("while constructing a Python object", mark,
|
||||
"cannot find module %r (%s)" % (module_name.encode('utf-8'), exc), mark)
|
||||
module = sys.modules[module_name]
|
||||
|
||||
@@ -155,7 +155,7 @@ class Reader(object):
|
||||
try:
|
||||
data, converted = self.raw_decode(self.raw_buffer,
|
||||
'strict', self.eof)
|
||||
except UnicodeDecodeError, exc:
|
||||
except UnicodeDecodeError as exc:
|
||||
character = exc.object[exc.start]
|
||||
if self.stream is not None:
|
||||
position = self.stream_pointer-len(self.raw_buffer)+exc.start
|
||||
|
||||
@@ -1424,7 +1424,7 @@ class Scanner(object):
|
||||
self.forward(2)
|
||||
try:
|
||||
value = unicode(''.join(bytes), 'utf-8')
|
||||
except UnicodeDecodeError, exc:
|
||||
except UnicodeDecodeError as exc:
|
||||
raise ScannerError("while scanning a %s" % name, start_mark, str(exc), mark)
|
||||
return value
|
||||
|
||||
|
||||
@@ -280,7 +280,7 @@ def main(argv):
|
||||
try:
|
||||
optlist, args = getopt.getopt(argv[1:], 'haVvqp:e:',
|
||||
['help', 'all', 'version', 'verbose', 'quiet', 'path=', 'exts='])
|
||||
except getopt.GetoptError, msg:
|
||||
except getopt.GetoptError as msg:
|
||||
sys.stderr.write("which: error: %s. Your invocation was: %s\n"\
|
||||
% (msg, argv))
|
||||
sys.stderr.write("Try 'which --help'.\n")
|
||||
|
||||
Reference in new issue
Block a user