From 99bf0a398030579f91dd212df9c25f0297f59e4f Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 11 Jan 2014 23:28:14 -0800 Subject: [PATCH 1/3] Made print statements python3 compatible in xattr.tool -- REfs #20 --- setup.py | 1 + xattr/tool.py | 44 +++++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/setup.py b/setup.py index bdfeb1a..364b028 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ from setuptools import setup from distutils.command.build import build + class cffi_build(build): """This is a shameful hack to ensure that cffi is present when we specify ext_modules. We can't do this eagerly because diff --git a/xattr/tool.py b/xattr/tool.py index 41ea7e1..a310506 100755 --- a/xattr/tool.py +++ b/xattr/tool.py @@ -25,6 +25,8 @@ # IN THE SOFTWARE. ## +from __future__ import print_function + import sys import os import getopt @@ -35,24 +37,24 @@ def usage(e=None): if e: - print e - print "" + print(e) + print("") name = os.path.basename(sys.argv[0]) - print "usage: %s [-lz] file [file ...]" % (name,) - print " %s -p [-lz] attr_name file [file ...]" % (name,) - print " %s -w [-z] attr_name attr_value file [file ...]" % (name,) - print " %s -d attr_name file [file ...]" % (name,) - print "" - print "The first form lists the names of all xattrs on the given file(s)." - print "The second form (-p) prints the value of the xattr attr_name." - print "The third form (-w) sets the value of the xattr attr_name to attr_value." - print "The fourth form (-d) deletes the xattr attr_name." - print "" - print "options:" - print " -h: print this help" - print " -l: print long format (attr_name: attr_value)" - print " -z: compress or decompress (if compressed) attribute value in zip format" + print("usage: %s [-lz] file [file ...]" % (name,)) + print(" %s -p [-lz] attr_name file [file ...]" % (name,)) + print(" %s -w [-z] attr_name attr_value file [file ...]" % (name,)) + print(" %s -d attr_name file [file ...]" % (name,)) + print("") + print("The first form lists the names of all xattrs on the given file(s).") + print("The second form (-p) prints the value of the xattr attr_name.") + print("The third form (-w) sets the value of the xattr attr_name to attr_value.") + print("The fourth form (-d) deletes the xattr attr_name.") + print("") + print("options:") + print(" -h: print this help") + print(" -l: print long format (attr_name: attr_value)") + print(" -z: compress or decompress (if compressed) attribute value in zip format") if e: sys.exit(64) @@ -191,15 +193,15 @@ def onError(e): try: if attr_value.find('\0') >= 0: raise NullsInString - print "".join((file_prefix, "%s: " % (attr_name,), attr_value)) + print("".join((file_prefix, "%s: " % (attr_name,), attr_value))) except (UnicodeDecodeError, NullsInString): - print "".join((file_prefix, "%s:" % (attr_name,))) - print _dump(attr_value) + print("".join((file_prefix, "%s:" % (attr_name,)))) + print(_dump(attr_value)) else: if read: - print "".join((file_prefix, attr_value)) + print("".join((file_prefix, attr_value))) else: - print "".join((file_prefix, attr_name)) + print("".join((file_prefix, attr_name))) sys.exit(status) From a67bad6a6210b90334442be301489c0fab7bc6f0 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 11 Jan 2014 23:31:03 -0800 Subject: [PATCH 2/3] Fixed exception syntax --- xattr/tool.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xattr/tool.py b/xattr/tool.py index a310506..ce8b8e6 100755 --- a/xattr/tool.py +++ b/xattr/tool.py @@ -82,7 +82,7 @@ def _dump(src, length=16): def main(): try: (optargs, args) = getopt.getopt(sys.argv[1:], "hlpwdz", ["help"]) - except getopt.GetoptError, e: + except getopt.GetoptError as e: usage(e) attr_name = None @@ -143,21 +143,21 @@ def onError(e): try: attrs = xattr.xattr(filename) - except (IOError, OSError), e: + except (IOError, OSError) as e: onError(e) continue if write: try: attrs[attr_name] = compress(attr_value) - except (IOError, OSError), e: + except (IOError, OSError) as e: onError(e) continue elif delete: try: del attrs[attr_name] - except (IOError, OSError), e: + except (IOError, OSError) as e: onError(e) continue except KeyError: @@ -170,7 +170,7 @@ def onError(e): attr_names = (attr_name,) else: attr_names = attrs.keys() - except (IOError, OSError), e: + except (IOError, OSError) as e: onError(e) continue From 6321e216e238ca9ecb3de2af4eee25a709b128c5 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 11 Jan 2014 23:32:07 -0800 Subject: [PATCH 3/3] Revert some noise that snuck in --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index 364b028..bdfeb1a 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,6 @@ from setuptools import setup from distutils.command.build import build - class cffi_build(build): """This is a shameful hack to ensure that cffi is present when we specify ext_modules. We can't do this eagerly because