From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 924451381F3 for ; Fri, 11 Oct 2013 10:33:15 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 51EDCE0A03; Fri, 11 Oct 2013 10:33:14 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id C4CF1E0A10 for ; Fri, 11 Oct 2013 10:33:13 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D958E33EFA5 for ; Fri, 11 Oct 2013 10:33:12 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 88483E5465 for ; Fri, 11 Oct 2013 10:33:11 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1381487375.3416b283af77915e14fb11b499f9a165236934dd.vapier@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/xattr-helper.py X-VCS-Directories: bin/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 3416b283af77915e14fb11b499f9a165236934dd X-VCS-Branch: master Date: Fri, 11 Oct 2013 10:33:11 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: a1649e52-10b7-41e9-97cf-84f99cd97b52 X-Archives-Hash: b64a48c9a4dac696769b34d26fa6e970 commit: 3416b283af77915e14fb11b499f9a165236934dd Author: Mike Frysinger gentoo org> AuthorDate: Fri Oct 11 10:29:35 2013 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Fri Oct 11 10:29:35 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=3416b283 xattr-helper: refactor dump_xattrs to make it a bit more readable Pull the common qoute chars out into a var and use % with format strings rather than mixing + in between. --- bin/xattr-helper.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bin/xattr-helper.py b/bin/xattr-helper.py index 249ea87..e84d23d 100755 --- a/bin/xattr-helper.py +++ b/bin/xattr-helper.py @@ -105,6 +105,9 @@ def unquote(s): def dump_xattrs(file_in, file_out): """Dump the xattr data for files in |file_in| to |file_out|""" + # NOTE: Always quote backslashes, in order to ensure that they are + # not interpreted as quotes when they are processed by unquote. + quote_chars = b'\n\r\\\\' for pathname in file_in.read().split(b'\0'): if not pathname: @@ -114,13 +117,14 @@ def dump_xattrs(file_in, file_out): if not attrs: continue - # NOTE: Always quote backslashes, in order to ensure that they are - # not interpreted as quotes when they are processed by unquote. - file_out.write(b'# file: ' + quote(pathname, b'\n\r\\\\') + b'\n') + file_out.write(b'# file: %s\n' % quote(pathname, quote_chars)) for attr in attrs: attr = unicode_encode(attr) - file_out.write(quote(attr, b'=\n\r\\\\') + b'="' + - quote(xattr.get(pathname, attr), b'\0\n\r"\\\\') + b'"\n') + value = xattr.get(pathname, attr) + file_out.write(b'%s="%s"\n' % ( + quote(attr, b'=' + quote_chars), + quote(value, b'\0"' + quote_chars))) + def restore_xattrs(file_in): """Read |file_in| and restore xattrs content from it