summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornyov <nyov@nexnode.net>2016-07-16 23:00:54 +0000
committernyov <nyov@nexnode.net>2016-07-16 23:00:54 +0000
commit5721ddee0441130eeeef6f4a9a20e4a69fccbc21 (patch)
treeb8d632045d3ff36b663cd52511291a52730734bd
parent3bd115acf29857c1506e40f001e0bdce9a798a34 (diff)
downloadxattr-5721ddee0441130eeeef6f4a9a20e4a69fccbc21.tar.gz
Fix Python3 bytes handling in xattr-tool.py
-rwxr-xr-xxattr/tool.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/xattr/tool.py b/xattr/tool.py
index 573261f..5cdecbd 100755
--- a/xattr/tool.py
+++ b/xattr/tool.py
@@ -3,7 +3,7 @@
##
# Copyright (c) 2007 Apple Inc.
#
-# This is the MIT license. This software may also be distributed under the
+# This is the MIT license. This software may also be distributed under the
# same terms as Python (the PSF license).
#
# Permission is hereby granted, free of charge, to any person obtaining a
@@ -35,6 +35,10 @@ import zlib
import xattr
+class NullsInString(Exception):
+ """Nulls in string."""
+
+
def usage(e=None):
if e:
print(e)
@@ -62,10 +66,6 @@ def usage(e=None):
sys.exit(0)
-class NullsInString(Exception):
- """Nulls in string."""
-
-
_FILTER = ''.join([(len(repr(chr(x))) == 3) and chr(x) or '.' for x in range(256)])
@@ -127,7 +127,7 @@ def main():
if write:
if not args:
usage("No attr_value")
- attr_value = args.pop(0)
+ attr_value = args.pop(0).encode('utf-8')
if len(args) > 1:
multiple_files = True
@@ -185,13 +185,14 @@ def main():
attr_value = decompress(attrs[attr_name])
except zlib.error:
attr_value = attrs[attr_name]
+ attr_value = attr_value.decode('utf-8')
except KeyError:
onError("%sNo such xattr: %s" % (file_prefix, attr_name))
continue
if long_format:
try:
- if attr_value.find('\0') >= 0:
+ if '\0' in attr_value:
raise NullsInString
print("".join((file_prefix, "%s: " % (attr_name,), attr_value)))
except (UnicodeDecodeError, NullsInString):