Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Work towards Python 3 compatibility. Since we already require Python …
Browse files Browse the repository at this point in the history
…2.7+,

we can use the new syntax without further limiting our Python 2 support.

* contrib/client-side/incremental-update.py
* contrib/client-side/svn_apply_autoprops.py
* contrib/client-side/svnmerge/svnmerge-migrate-history.py
* contrib/client-side/svnmerge/svnmerge-migrate-history-remotely.py
* contrib/client-side/svnmerge/svnmerge.py
* contrib/client-side/svnmerge/svnmerge_test.py
* contrib/server-side/add-needs-lock.py
* contrib/server-side/fsfsfixer/fixer/fix-rev.py
* contrib/server-side/fsfsverify.py
* contrib/server-side/svn-tweak-author.py
* subversion/bindings/swig/python/tests/core.py
* subversion/bindings/swig/python/tests/repository.py
* subversion/tests/cmdline/svntest/actions.py
* subversion/tests/cmdline/svntest/main.py
* subversion/tests/cmdline/svntest/objects.py
* subversion/tests/cmdline/svntest/wc.py
* subversion/tests/cmdline/upgrade_tests.py
* tools/client-side/change-svn-wc-format.py
* tools/client-side/mergeinfo-sanitizer.py
* tools/dev/contribulyze.py
* tools/dev/gen-javahl-errors.py
* tools/dev/gen_junit_report.py
* tools/dev/graph-dav-servers.py
* tools/dev/iz/ff2csv.py
* tools/dev/iz/find-fix.py
* tools/dev/wc-ng/bump-to-19.py
* tools/dev/wc-ng/populate-pristine.py
* tools/dev/which-error.py
* tools/examples/get-location-segments.py
* tools/hook-scripts/svn2feed.py
* tools/hook-scripts/svnperms.py
* tools/po/l10n-report.py
* tools/server-side/fsfs-reshard.py
* tools/server-side/svn-backup-dumps.py
* tools/server-side/svnpredumpfilter.py
* tools/server-side/svnpubsub/daemonize.py
* tools/server-side/test_svn_server_log_parse.py
  ():  Replace all occurances of "except Type, variable:" with Python 3
       style "except Type as variable".


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1741723 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Stefan Fuhrmann committed Apr 30, 2016
1 parent e6c48a4 commit 90662b5
Show file tree
Hide file tree
Showing 37 changed files with 72 additions and 72 deletions.
2 changes: 1 addition & 1 deletion contrib/client-side/incremental-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,6 @@ def main():
main()
except SystemExit:
raise
except Exception, e:
except Exception as e:
print_error(str(e))
sys.exit(1)
2 changes: 1 addition & 1 deletion contrib/client-side/svn_apply_autoprops.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def filter_walk(autoprop_lines, dirname, filenames):
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], 'h', ['help', 'config='])
except getopt.GetoptError, e:
except getopt.GetoptError as e:
usage()
return 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def migrate_path(self, path):
sys.stdout.write(" new sanitized chunk:\n")
pretty_print_mergeinfo(history, 6)
new_mergeinfo = mergeinfo_merge(new_mergeinfo, history)
except core.SubversionException, e:
except core.SubversionException as e:
if not (e.apr_err == core.SVN_ERR_FS_NOT_FOUND
or e.apr_err == core.SVN_ERR_FS_NO_SUCH_REVISION):
raise
Expand Down
4 changes: 2 additions & 2 deletions contrib/client-side/svnmerge/svnmerge-migrate-history.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import svn.core
import svn.fs
import svn.repos
except ImportError, e:
except ImportError as e:
print >> sys.stderr, \
"ERROR: Unable to import Subversion's Python bindings: '%s'\n" \
"Hint: Set your PYTHONPATH environment variable, or adjust your " \
Expand Down Expand Up @@ -230,7 +230,7 @@ def convert_path_history(self, root, revnum, path):
filtered_mergeinfo = \
svn.core.svn_mergeinfo_merge(filtered_mergeinfo,
source_history)
except svn.core.SubversionException, e:
except svn.core.SubversionException as e:
if not (e.apr_err == svn.core.SVN_ERR_FS_NOT_FOUND
or e.apr_err == svn.core.SVN_ERR_FS_NO_SUCH_REVISION):
raise
Expand Down
6 changes: 3 additions & 3 deletions contrib/client-side/svnmerge/svnmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def launch(cmd, split_lines=True):
stdoutAndErr = p.communicate()
stdout = stdoutAndErr[0]
stderr = stdoutAndErr[1]
except OSError, inst:
except OSError as inst:
# Using 1 as failure code; should get actual number somehow? For
# examples see svnmerge_test.py's TestCase_launch.test_failure and
# TestCase_launch.test_failurecode.
Expand Down Expand Up @@ -1960,7 +1960,7 @@ def parse(self, args):
opts.extend(cmd.opts)
args.remove(cmd.name)
state, args = self._fancy_getopt(args, opts)
except getopt.GetoptError, e:
except getopt.GetoptError as e:
self.error(e, cmd)

# Handle builtins
Expand Down Expand Up @@ -2367,7 +2367,7 @@ def main(args):
if __name__ == "__main__":
try:
main(sys.argv[1:])
except LaunchError, (ret, cmd, out):
except LaunchError as (ret, cmd, out):
err_msg = "command execution failed (exit code: %d)\n" % ret
err_msg += cmd + "\n"
err_msg += "".join(out)
Expand Down
6 changes: 3 additions & 3 deletions contrib/client-side/svnmerge/svnmerge_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_failure(self):
def test_failurecode(self):
try:
svnmerge.launch(self.cmd*10)
except svnmerge.LaunchError, (ret, cmd, out):
except svnmerge.LaunchError as (ret, cmd, out):
self.assertNotEqual(ret, 0)
self.assertNotEqual(ret, None)
self.assert_(out)
Expand Down Expand Up @@ -254,7 +254,7 @@ def svnmerge2(self, args, error=False, match=None, nonmatch=None):
reset_svnmerge()

ret = svnmerge.main(args)
except SystemExit, e:
except SystemExit as e:
ret = e.code
finally:
sys.stdout = sys.__stdout__
Expand Down Expand Up @@ -302,7 +302,7 @@ def _parseoutput(self, ret, out, error=False, match=None, nonmatch=None):
def launch(self, cmd, **kwargs):
try:
out = svnmerge.launch(cmd, split_lines=False)
except svnmerge.LaunchError, (ret, cmd, out):
except svnmerge.LaunchError as (ret, cmd, out):
return self._parseoutput(ret, out, **kwargs)
return self._parseoutput(0, out, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion contrib/server-side/add-needs-lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import svn.core
import svn.fs
import svn.repos
except ImportError, e:
except ImportError as e:
print >> sys.stderr, "ERROR: Unable to import Subversion's Python bindings: '%s'" % e
sys.exit(1)

Expand Down
4 changes: 2 additions & 2 deletions contrib/server-side/fsfsfixer/fixer/fix-rev.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def fix_one_error(repo_dir, rev):
return True
else:
verbose_print("Unrecognized error message; trying 'svnlook' instead.")
except FixError, e:
except FixError as e:
print 'warning:', e
verbose_print("Trying 'svnlook' instead.")

Expand Down Expand Up @@ -295,6 +295,6 @@ def fix_rev(repo_dir, rev):

try:
fix_rev(repo_dir, rev)
except FixError, e:
except FixError as e:
print 'error:', e
sys.exit(1)
14 changes: 7 additions & 7 deletions contrib/server-side/fsfsverify.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def __init__(self, byteStream, svndiffVersion):
self.instrByteStream = ZlibByteStream(self.origInstrStream,
self.compressedInstrLength)
self.isInstrCompressed = True
except Exception, e:
except Exception as e:
new_e = InvalidCompressedStream(
"Invalid compressed instr stream at offset %d (%s)" % (offset,
str(e)),
Expand All @@ -359,7 +359,7 @@ def __init__(self, byteStream, svndiffVersion):
self.dataByteStream = ZlibByteStream(self.origDataStream,
self.compressedDataLength)
self.isDataCompressed = True
except Exception, e:
except Exception as e:
new_e = InvalidCompressedStream(
"Invalid compressed data stream at offset %d (%s, %s)\n" % (
offset, str(e), repr(self)),
Expand Down Expand Up @@ -388,7 +388,7 @@ def verify(self):
while computedInstrLength < expectedInstrLength:
try:
instr = SvndiffInstruction(self.instrByteStream)
except PotentiallyFixableException, e:
except PotentiallyFixableException as e:
e.window = self
e.windowOffset = self.windowOffset
raise
Expand Down Expand Up @@ -492,7 +492,7 @@ def verify(self):
log(LOG_WINDOWS, 3, repr(w))
w.verify()
remaining -= w.windowLength
except PotentiallyFixableException, e:
except PotentiallyFixableException as e:
e.svndiffStart = self.startingOffset
raise

Expand Down Expand Up @@ -580,7 +580,7 @@ def verify(self, f, dumpInstructions, dumpWindows):
try:
svndiff = Svndiff(f, self.length)
svndiff.verify()
except Exception, e:
except Exception as e:
e.rep = self
e.noderev = self.noderev
raise
Expand Down Expand Up @@ -1209,13 +1209,13 @@ def handleError(error, withTraceback=False):
except:
sys.stdout.flush()
raise
except InvalidRepHeader, e:
except InvalidRepHeader as e:
if not options.fixRlle:
handleError(e, options.showTraceback)

fixHeader(e, revFile)

except PotentiallyFixableException, e:
except PotentiallyFixableException as e:
if not options.fixRlle:
handleError(e, options.showTraceback)

Expand Down
2 changes: 1 addition & 1 deletion contrib/server-side/svn-tweak-author.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def main():
usage_and_exit("Invalid mode (%s) provided." % (mode))
except SystemExit:
raise
except Exception, e:
except Exception as e:
error_and_exit(str(e))

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion subversion/bindings/swig/python/tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __call__(self, path, info, pool):
# It must remain unchanged through the process.
try:
svn.client.info2(*args)
except svn.core.SubversionException, exc:
except svn.core.SubversionException as exc:
# find the original exception
while exc.file != rec.e.file: exc = exc.child

Expand Down
2 changes: 1 addition & 1 deletion subversion/bindings/swig/python/tests/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def test_lock_unlock(self):
fs.lock(self.fs, '/trunk/README.txt', None, None, 0, 0, self.rev, False)
try:
fs.lock(self.fs, '/trunk/README.txt', None, None, 0, 0, self.rev, False)
except core.SubversionException, exc:
except core.SubversionException as exc:
self.assertEqual(exc.apr_err, core.SVN_ERR_FS_PATH_ALREADY_LOCKED)
fs.lock(self.fs, '/trunk/README.txt', None, None, 0, 0, self.rev, True)

Expand Down
4 changes: 2 additions & 2 deletions subversion/tests/cmdline/svntest/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ def parse(self, data):
for i in data:
self.parser.Parse(i)
self.parser.Parse('', True)
except xml.parsers.expat.ExpatError, e:
except xml.parsers.expat.ExpatError as e:
raise verify.SVNUnexpectedStdout('%s\n%s\n' % (e, ''.join(data),))
return self.entries

Expand Down Expand Up @@ -1889,7 +1889,7 @@ def make_repo_and_wc(sbox, create_wc=True, read_only=False, empty=False,
# just make sure the parent folder of our working copy is created
try:
os.mkdir(main.general_wc_dir)
except OSError, err:
except OSError as err:
if err.errno != errno.EEXIST:
raise

Expand Down
8 changes: 4 additions & 4 deletions subversion/tests/cmdline/svntest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def wrap_ex(func, output):
def w(*args, **kwds):
try:
return func(*args, **kwds)
except Failure, ex:
except Failure as ex:
if ex.__class__ != Failure or ex.args:
ex_args = str(ex)
if ex_args:
Expand Down Expand Up @@ -1786,9 +1786,9 @@ def run(self):
print('Test driver returned a status code.')
sys.exit(255)
result = svntest.testcase.RESULT_OK
except Skip, ex:
except Skip as ex:
result = svntest.testcase.RESULT_SKIP
except Failure, ex:
except Failure as ex:
result = svntest.testcase.RESULT_FAIL
msg = ''
# We captured Failure and its subclasses. We don't want to print
Expand All @@ -1806,7 +1806,7 @@ def run(self):
except KeyboardInterrupt:
logger.error('Interrupted')
sys.exit(0)
except SystemExit, ex:
except SystemExit as ex:
logger.error('EXCEPTION: SystemExit(%d), skipping cleanup' % ex.code)
self._print_name(ex.code and 'FAIL: ' or 'PASS: ')
raise
Expand Down
2 changes: 1 addition & 1 deletion subversion/tests/cmdline/svntest/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def locate_db_dump():
try:
if subprocess.Popen([db_dump_name, "-V"]).wait() == 0:
return db_dump_name
except OSError, e:
except OSError as e:
pass
return 'none'

Expand Down
2 changes: 1 addition & 1 deletion subversion/tests/cmdline/svntest/wc.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def tweak(self, *args, **kw):
for path in args:
try:
path_ref = self.desc[to_relpath(path)]
except KeyError, e:
except KeyError as e:
e.args = ["Path '%s' not present in WC state descriptor" % path]
raise
path_ref.tweak(**kw)
Expand Down
4 changes: 2 additions & 2 deletions subversion/tests/cmdline/upgrade_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def replace_sbox_with_tarfile(sbox, tar_filename,
dir=None):
try:
svntest.main.safe_rmtree(sbox.wc_dir)
except OSError, e:
except OSError as e:
pass

if not dir:
Expand All @@ -81,7 +81,7 @@ def replace_sbox_with_tarfile(sbox, tar_filename,
def replace_sbox_repo_with_tarfile(sbox, tar_filename, dir=None):
try:
svntest.main.safe_rmtree(sbox.repo_dir)
except OSError, e:
except OSError as e:
pass

if not dir:
Expand Down
6 changes: 3 additions & 3 deletions tools/client-side/change-svn-wc-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def write_dir_format(self, format_nbr, dirname, paths):
print("Parsing file '%s'" % entries.path)
try:
entries.parse(self.verbosity)
except UnrecognizedWCFormatException, e:
except UnrecognizedWCFormatException as e:
if self.error_on_unrecognized:
raise
sys.stderr.write("%s, skipping\n" % e)
Expand All @@ -116,7 +116,7 @@ def write_dir_format(self, format_nbr, dirname, paths):
print("Checking whether WC format can be converted")
try:
entries.assert_valid_format(format_nbr, self.verbosity)
except LossyConversionException, e:
except LossyConversionException as e:
# In --force mode, ignore complaints about lossy conversion.
if self.force:
print("WARNING: WC format conversion will be lossy. Dropping "\
Expand Down Expand Up @@ -405,7 +405,7 @@ def main():

try:
converter.change_wc_format(new_format_nbr)
except LocalException, e:
except LocalException as e:
if debug:
raise
sys.stderr.write("%s\n" % e)
Expand Down
8 changes: 4 additions & 4 deletions tools/client-side/mergeinfo-sanitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def get_new_location_segments(parsed_original_mergeinfo, repo_root,
revision_range.end, revision_range.start + 1, location_segment_callback)
except svn.core.SubversionException:
sys.stderr.write(" Could not find location segments for %s \n" % path)
except Exception, e:
except Exception as e:
sys.stderr.write("")


Expand Down Expand Up @@ -204,7 +204,7 @@ def fix_sanitized_mergeinfo(parsed_original_mergeinfo, repo_root, wcpath,
with open(hash_file, "r") as f:
old_hash = pickle.load(f)
f.close
except IOError, e:
except IOError as e:
get_new_location_segments(parsed_original_mergeinfo, repo_root, wcpath, ctx)
hasher(hash_file, newmergeinfo_file)
try:
Expand All @@ -217,7 +217,7 @@ def fix_sanitized_mergeinfo(parsed_original_mergeinfo, repo_root, wcpath,
with open(newmergeinfo_file, "r") as f:
new_hash = md5_of_file(f)
f.close
except IOError, e:
except IOError as e:
if not mergeinfo:
get_new_location_segments(parsed_original_mergeinfo, repo_root, wcpath, ctx)
hasher(hash_file, newmergeinfo_file)
Expand Down Expand Up @@ -263,7 +263,7 @@ def get_original_mergeinfo(wcpath, revision, depth, ctx, temp_pool):
def main():
try:
opts, args = my_getopt(sys.argv[1:], "h?f", ["help", "fix"])
except Exception, e:
except Exception as e:
sys.stderr.write(""" Improperly used """)
sys.exit(1)

Expand Down
2 changes: 1 addition & 1 deletion tools/dev/contribulyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def usage():
def main():
try:
opts, args = my_getopt(sys.argv[1:], 'C:U:hH?', [ 'help' ])
except getopt.GetoptError, e:
except getopt.GetoptError as e:
complain(str(e) + '\n\n')
usage()
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion tools/dev/gen-javahl-errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

try:
from svn import core
except ImportError, e:
except ImportError as e:
sys.stderr.write("ERROR: Unable to import Subversion's Python bindings: '%s'\n" \
"Hint: Set your PYTHONPATH environment variable, or adjust your " \
"PYTHONSTARTUP\nfile to point to your Subversion install " \
Expand Down
Loading

0 comments on commit 90662b5

Please sign in to comment.