Skip to content

Commit

Permalink
updated all python files to use pep-3110 exception syntax for python3…
Browse files Browse the repository at this point in the history
… compatibility
  • Loading branch information
heartsucker committed Mar 29, 2019
1 parent 7511b59 commit c5a8469
Show file tree
Hide file tree
Showing 42 changed files with 139 additions and 94 deletions.
4 changes: 2 additions & 2 deletions misc/coding_tools/check-interfaces.py
Expand Up @@ -46,7 +46,7 @@ def _implements_advice(cls):
for interface in interfaces:
try:
verifyClass(interface, cls)
except Exception, e:
except Exception as e:
print("%s.%s does not correctly implement %s.%s:\n%s"
% (cls.__module__, cls.__name__,
interface.__module__, interface.__name__, e), file=_err)
Expand Down Expand Up @@ -89,7 +89,7 @@ def check():
module = relpath.replace(os.sep, '/').replace('/', '.')
try:
__import__(module)
except ImportError, e:
except ImportError as e:
if not is_windows and (' _win' in str(e) or 'win32' in str(e)):
print("Warning: %r imports a Windows-specific module, so we cannot check it (%s).\n"
% (module, str(e)), file=_err)
Expand Down
2 changes: 1 addition & 1 deletion misc/coding_tools/check-miscaptures.py
Expand Up @@ -15,7 +15,7 @@ def check_file(path):
def check_thing(parser, thing):
try:
ast = parser(thing)
except SyntaxError, e:
except SyntaxError as e:
return e
else:
results = []
Expand Down
1 change: 1 addition & 0 deletions newsfragments/3013.other
@@ -0,0 +1 @@
Updated all Python files to use PEP-3110 exception syntax for Python3 compatibility.
69 changes: 56 additions & 13 deletions py3_valid_syntax.txt
@@ -1,21 +1,18 @@
docs/
integration/
misc/build_helpers/check-build.py
misc/build_helpers/gen-package-table.py
misc/build_helpers/run-deprecations.py
misc/build_helpers/show-tool-versions.py
misc/build_helpers/test-osx-pkg.py
misc/coding_tools/check-debugging.py
misc/coding_tools/coverage2el.py
misc/coding_tools/fixshebangs.py
misc/coding_tools/graph-deps.py
misc/incident-gatherer/classify_tahoe.py
misc/operations_helpers/provisioning/provisioning.py
misc/operations_helpers/provisioning/reliability.py
misc/operations_helpers/provisioning/run.py
misc/operations_helpers/provisioning/test_provisioning.py
misc/operations_helpers/provisioning/util.py
misc/operations_helpers/provisioning/web_reliability.py
misc/operations_helpers/spacetime/diskwatcher.py
misc/coding_tools/
misc/incident-gatherer/
misc/operations_helpers/
misc/simulators/
release-tools/
setup.py
src/allmydata/_auto_deps.py
src/allmydata/blacklist.py
src/allmydata/check_results.py
src/allmydata/client.py
src/allmydata/codec.py
Expand All @@ -25,10 +22,12 @@ src/allmydata/frontends/auth.py
src/allmydata/frontends/__init__.py
src/allmydata/hashtree.py
src/allmydata/history.py
src/allmydata/immutable/checker.py
src/allmydata/immutable/downloader/common.py
src/allmydata/immutable/downloader/fetcher.py
src/allmydata/immutable/downloader/finder.py
src/allmydata/immutable/downloader/__init__.py
src/allmydata/immutable/downloader/share.py
src/allmydata/immutable/downloader/status.py
src/allmydata/immutable/filenode.py
src/allmydata/immutable/__init__.py
Expand All @@ -38,6 +37,7 @@ src/allmydata/immutable/offloaded.py
src/allmydata/immutable/repairer.py
src/allmydata/interfaces.py
src/allmydata/introducer/
src/allmydata/magicfolderdb.py
src/allmydata/__main__.py
src/allmydata/monitor.py
src/allmydata/mutable/checker.py
Expand All @@ -46,23 +46,45 @@ src/allmydata/mutable/__init__.py
src/allmydata/mutable/layout.py
src/allmydata/mutable/publish.py
src/allmydata/mutable/repairer.py
src/allmydata/mutable/retrieve.py
src/allmydata/mutable/servermap.py
src/allmydata/nodemaker.py
src/allmydata/scripts/admin.py
src/allmydata/scripts/backupdb.py
src/allmydata/scripts/cli.py
src/allmydata/scripts/common_http.py
src/allmydata/scripts/common.py
src/allmydata/scripts/default_nodedir.py
src/allmydata/scripts/__init__.py
src/allmydata/scripts/magic_folder_cli.py
src/allmydata/scripts/slow_operation.py
src/allmydata/scripts/stats_gatherer.py
src/allmydata/scripts/tahoe_add_alias.py
src/allmydata/scripts/tahoe_backup.py
src/allmydata/scripts/tahoe_check.py
src/allmydata/scripts/tahoe_cp.py
src/allmydata/scripts/tahoe_daemonize.py
src/allmydata/scripts/tahoe_get.py
src/allmydata/scripts/tahoe_invite.py
src/allmydata/scripts/tahoe_ls.py
src/allmydata/scripts/tahoe_manifest.py
src/allmydata/scripts/tahoe_mkdir.py
src/allmydata/scripts/tahoe_mv.py
src/allmydata/scripts/tahoe_put.py
src/allmydata/scripts/tahoe_restart.py
src/allmydata/scripts/tahoe_run.py
src/allmydata/scripts/tahoe_start.py
src/allmydata/scripts/tahoe_status.py
src/allmydata/storage_client.py
src/allmydata/scripts/tahoe_stop.py
src/allmydata/scripts/tahoe_unlink.py
src/allmydata/scripts/tahoe_webopen.py
src/allmydata/stats.py
src/allmydata/storage/
src/allmydata/test/bench_dirnode.py
src/allmydata/test/check_grid.py
src/allmydata/test/check_load.py
src/allmydata/test/check_memory.py
src/allmydata/test/check_speed.py
src/allmydata/test/cli/common.py
src/allmydata/test/cli/__init__.py
src/allmydata/test/cli/test_alias.py
Expand All @@ -71,6 +93,8 @@ src/allmydata/test/cli/test_daemonize.py
src/allmydata/test/cli/test_invite.py
src/allmydata/test/cli/test_start.py
src/allmydata/test/cli/test_status.py
src/allmydata/test/common.py
src/allmydata/test/common_util.py
src/allmydata/test/common_web.py
src/allmydata/test/eliotutil.py
src/allmydata/test/__init__.py
Expand All @@ -85,7 +109,10 @@ src/allmydata/test/mutable/test_interoperability.py
src/allmydata/test/mutable/test_multiple_encodings.py
src/allmydata/test/mutable/test_multiple_versions.py
src/allmydata/test/mutable/test_repair.py
src/allmydata/test/mutable/test_roundtrip.py
src/allmydata/test/mutable/test_servermap.py
src/allmydata/test/mutable/test_update.py
src/allmydata/test/mutable/test_version.py
src/allmydata/test/mutable/util.py
src/allmydata/test/plugins/tahoe_lafs_dropin.py
src/allmydata/test/status.py
Expand All @@ -95,10 +122,13 @@ src/allmydata/test/test_checker.py
src/allmydata/test/test_client.py
src/allmydata/test/test_configutil.py
src/allmydata/test/test_connections.py
src/allmydata/test/test_crawler.py
src/allmydata/test/test_eliotutil.py
src/allmydata/test/test_encode.py
src/allmydata/test/test_encodingutil.py
src/allmydata/test/test_filenode.py
src/allmydata/test/test_happiness.py
src/allmydata/test/test_hashtree.py
src/allmydata/test/test_helper.py
src/allmydata/test/test_hung_server.py
src/allmydata/test/test_i2p_provider.py
Expand All @@ -113,6 +143,7 @@ src/allmydata/test/test_multi_introducers.py
src/allmydata/test/test_netstring.py
src/allmydata/test/test_no_network.py
src/allmydata/test/test_observer.py
src/allmydata/test/test_repairer.py
src/allmydata/test/test_runner.py
src/allmydata/test/test_stats.py
src/allmydata/test/test_storage_client.py
Expand All @@ -121,24 +152,32 @@ src/allmydata/test/test_uri.py
src/allmydata/test/test_version.py
src/allmydata/test/web/common.py
src/allmydata/test/web/__init__.py
src/allmydata/test/web/matchers.py
src/allmydata/test/web/test_grid.py
src/allmydata/test/web/test_introducer.py
src/allmydata/test/web/test_logs.py
src/allmydata/test/web/test_private.py
src/allmydata/test/web/test_root.py
src/allmydata/test/web/test_token.py
src/allmydata/test/web/test_util.py
src/allmydata/unknown.py
src/allmydata/uri.py
src/allmydata/util/abbreviate.py
src/allmydata/util/base32.py
src/allmydata/util/base62.py
src/allmydata/util/cachedir.py
src/allmydata/util/configutil.py
src/allmydata/util/connection_status.py
src/allmydata/util/consumer.py
src/allmydata/util/dbutil.py
src/allmydata/util/deferredutil.py
src/allmydata/util/dictutil.py
src/allmydata/util/eliotutil.py
src/allmydata/util/hashutil.py
src/allmydata/util/i2p_provider.py
src/allmydata/util/idlib.py
src/allmydata/util/__init__.py
src/allmydata/util/iputil.py
src/allmydata/util/keyutil.py
src/allmydata/util/limiter.py
src/allmydata/util/log.py
Expand All @@ -149,6 +188,7 @@ src/allmydata/util/nummedobj.py
src/allmydata/util/observer.py
src/allmydata/util/pipeline.py
src/allmydata/util/pkgresutil.py
src/allmydata/util/pollmixin.py
src/allmydata/util/progress.py
src/allmydata/util/repeatable_random.py
src/allmydata/util/rrefutil.py
Expand All @@ -157,9 +197,12 @@ src/allmydata/util/statistics.py
src/allmydata/util/tor_provider.py
src/allmydata/util/verlib.py
src/allmydata/util/yamlutil.py
src/allmydata/_version.py
src/allmydata/watchdog/
src/allmydata/web/
src/allmydata/webish.py
src/allmydata/windows/__init__.py
src/allmydata/windows/tahoesvc.py
static/
static/tahoe.py
ws_client.py
6 changes: 3 additions & 3 deletions src/allmydata/__init__.py
Expand Up @@ -399,7 +399,7 @@ def cross_check(pkg_resources_vers_and_locs, imported_vers_and_locs_list):
pr_normver = normalized_version(pr_ver)
except verlib.IrrationalVersionError:
continue
except Exception, e:
except Exception as e:
errors.append("Warning: version number %r found for dependency %r by pkg_resources could not be parsed. "
"The version found by import was %r from %r. "
"pkg_resources thought it should be found at %r. "
Expand All @@ -416,7 +416,7 @@ def cross_check(pkg_resources_vers_and_locs, imported_vers_and_locs_list):
imp_normver = normalized_version(imp_ver)
except verlib.IrrationalVersionError:
continue
except Exception, e:
except Exception as e:
errors.append("Warning: version number %r found for dependency %r (imported from %r) could not be parsed. "
"pkg_resources thought it should be version %r at %r. "
"The exception was %s: %s"
Expand Down Expand Up @@ -470,7 +470,7 @@ def check_all_requirements():
for requirement in install_requires:
try:
check_requirement(requirement, vers_and_locs)
except (ImportError, PackagingError), e:
except (ImportError, PackagingError) as e:
fatal_errors.append("%s: %s" % (e.__class__.__name__, e))

if fatal_errors:
Expand Down
2 changes: 1 addition & 1 deletion src/allmydata/blacklist.py
Expand Up @@ -42,7 +42,7 @@ def read_blacklist(self):
si = base32.a2b(si_s) # must be valid base32
self.entries[si] = reason
self.last_mtime = current_mtime
except Exception, e:
except Exception as e:
twisted_log.err(e, "unparseable blacklist file")
raise

Expand Down
2 changes: 1 addition & 1 deletion src/allmydata/dirnode.py
Expand Up @@ -402,7 +402,7 @@ def _unpack_contents(self, data):
log.msg(format="mutable cap for child %(name)s unpacked from an immutable directory",
name=quote_output(name, encoding='utf-8'),
facility="tahoe.webish", level=log.UNUSUAL)
except CapConstraintError, e:
except CapConstraintError as e:
log.msg(format="unmet constraint on cap for child %(name)s unpacked from a directory:\n"
"%(message)s", message=e.args[0], name=quote_output(name, encoding='utf-8'),
facility="tahoe.webish", level=log.UNUSUAL)
Expand Down
2 changes: 1 addition & 1 deletion src/allmydata/frontends/sftpd.py
Expand Up @@ -536,7 +536,7 @@ def close(self):
self.is_closed = True
try:
self.f.close()
except Exception, e:
except Exception as e:
self.log("suppressed %r from close of temporary file %r" % (e, self.f), level=WEIRD)
self.download_done("closed")
return self.done_status
Expand Down
18 changes: 9 additions & 9 deletions src/allmydata/immutable/checker.py
Expand Up @@ -256,9 +256,9 @@ def _got_share_hashes(sh):
sharehashes = dict(sh)
try:
self.share_hash_tree.set_hashes(sharehashes)
except IndexError, le:
except IndexError as le:
raise BadOrMissingHash(le)
except (hashtree.BadHashError, hashtree.NotEnoughHashesError), le:
except (hashtree.BadHashError, hashtree.NotEnoughHashesError) as le:
raise BadOrMissingHash(le)
d.addCallback(_got_share_hashes)
return d
Expand Down Expand Up @@ -289,9 +289,9 @@ def _got_block_hashes(blockhashes):

try:
self.block_hash_tree.set_hashes(bh)
except IndexError, le:
except IndexError as le:
raise BadOrMissingHash(le)
except (hashtree.BadHashError, hashtree.NotEnoughHashesError), le:
except (hashtree.BadHashError, hashtree.NotEnoughHashesError) as le:
raise BadOrMissingHash(le)
d.addCallback(_got_block_hashes)
return d
Expand All @@ -316,9 +316,9 @@ def _got_crypttext_hashes(hashes):
ct_hashes = dict(enumerate(hashes))
try:
crypttext_hash_tree.set_hashes(ct_hashes)
except IndexError, le:
except IndexError as le:
raise BadOrMissingHash(le)
except (hashtree.BadHashError, hashtree.NotEnoughHashesError), le:
except (hashtree.BadHashError, hashtree.NotEnoughHashesError) as le:
raise BadOrMissingHash(le)
d.addCallback(_got_crypttext_hashes)
return d
Expand Down Expand Up @@ -359,7 +359,7 @@ def _got_data(self, results, blocknum):
sharehashes, blockhashes, blockdata = results
try:
sharehashes = dict(sharehashes)
except ValueError, le:
except ValueError as le:
le.args = tuple(le.args + (sharehashes,))
raise
blockhashes = dict(enumerate(blockhashes))
Expand All @@ -373,7 +373,7 @@ def _got_data(self, results, blocknum):
# match the root node of self.share_hash_tree.
try:
self.share_hash_tree.set_hashes(sharehashes)
except IndexError, le:
except IndexError as le:
# Weird -- sharehashes contained index numbers outside of
# the range that fit into this hash tree.
raise BadOrMissingHash(le)
Expand All @@ -400,7 +400,7 @@ def _got_data(self, results, blocknum):
# (self.sharenum, blocknum, len(blockdata),
# blockdata[:50], blockdata[-50:], base32.b2a(blockhash)))

except (hashtree.BadHashError, hashtree.NotEnoughHashesError), le:
except (hashtree.BadHashError, hashtree.NotEnoughHashesError) as le:
# log.WEIRD: indicates undetected disk/network error, or more
# likely a programming error
self.log("hash failure in block=%d, shnum=%d on %s" %
Expand Down

0 comments on commit c5a8469

Please sign in to comment.