From patchwork Thu Aug 4 18:33:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Zaman X-Patchwork-Id: 9264051 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B53E06048B for ; Thu, 4 Aug 2016 18:38:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A79F2283E4 for ; Thu, 4 Aug 2016 18:38:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C6E42841F; Thu, 4 Aug 2016 18:38:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from emsm-gh1-uea10.nsa.gov (smtp.nsa.gov [8.44.101.8]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7600283E4 for ; Thu, 4 Aug 2016 18:38:17 +0000 (UTC) Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea10.nsa.gov with ESMTP; 04 Aug 2016 18:38:15 +0000 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u74IcDWf011791; Thu, 4 Aug 2016 14:38:14 -0400 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u74IYPTi250300 for ; Thu, 4 Aug 2016 14:34:25 -0400 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u74IYMKV011354 for ; Thu, 4 Aug 2016 14:34:27 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1BhAQBGiqNXdELcVdFcHYJ7gQN8sSyFZIQMHIYBAoFITAEBAQEBARMBCgsUF4UQAgEDEi4BATcBD0ARNAEFARwZIogPAaEUgTI+MYpUhSoBAQWLRQEBAQEBBQIBHAgQhA+NYQuDB4gqhmaKKYYaiGplgVKHDYV6jmkwgQ+EW2EBhyoBAQE X-IPAS-Result: A1BhAQBGiqNXdELcVdFcHYJ7gQN8sSyFZIQMHIYBAoFITAEBAQEBARMBCgsUF4UQAgEDEi4BATcBD0ARNAEFARwZIogPAaEUgTI+MYpUhSoBAQWLRQEBAQEBBQIBHAgQhA+NYQuDB4gqhmaKKYYaiGplgVKHDYV6jmkwgQ+EW2EBhyoBAQE X-IronPort-AV: E=Sophos;i="5.28,471,1464667200"; d="scan'208";a="5626383" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 04 Aug 2016 14:35:14 -0400 Received: from mail-pa0-f66.google.com ([209.85.220.66]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/AES128-GCM-SHA256; 04 Aug 2016 18:34:25 +0000 Received: by mail-pa0-f66.google.com with SMTP id ez1so17903635pab.3 for ; Thu, 04 Aug 2016 11:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=perfinion-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rKBIQOgFFaZEhYq6B5VwnJMFpBIH9JF2CrnKj7ejvkw=; b=e131ghr5hmKAvABvFixfHleMep1Lj5CQK8FT5mD8v78podfp6dUKicD+flonaQKkQD +EVOTputZtl6AYopMf1IPrEb3HJ49V9iQQDc7Te6cFmVo8VZCjQrsorjrf8IhJh6ooJ9 Vn2qAIcoi7STQYsC7dtLAYe0GAiW7rK1hZ/oz6m/R6zlXwME+7tIAe5xFdf8+n3PpqPa pZX78+/L8jKkBxOJaOXLhdmp2duo2g7kkJiwPm507EwBHkXCPVCTGF6fCX+wGt4OoDp6 7TZFNkxFp4SfgCEnSMim60FAukgRjHIFs3Sy+SqgrKKlMI68UPCNFoK/Wig3a4U5qkQC JQvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rKBIQOgFFaZEhYq6B5VwnJMFpBIH9JF2CrnKj7ejvkw=; b=XMddqOMWOE+JBnSvRVMHPlMd2rLoHGyAdM3uMvwBgRqEPJ+bjk1F/0Cn9t1icgLc6z AjDZU48wROylR7wME/52L/HmwQPu3LVGqc/2zL+/2MJnkUyt236y+ynY2Yp9yJD2OOju N7IETkPVMMGNGWSwYhJeEFpzj1NYmGBI6EAazIU9BkVPKVN7wvLUJYba9Ontt1fosjE3 xIyhFj/Qj8s9fDXKUXmAn+3J6eyVNPLbDOOZ1cL657nVOD9vdP5CaM8D1gqudlSoW43z EOMWYMC/YAtZTehkIErBVXgNAzurmsujspt3JRrYYBW51CQOCdfYTrnhBncOk0i+aVio n2/A== X-Gm-Message-State: AEkooutSYMMNKYUWcp2Tt8cbZDK6W6PWxpisRy9WZR2ChsFCW3Z0SeF+3stikZm0IdMdeA== X-Received: by 10.66.219.105 with SMTP id pn9mr127573352pac.25.1470335664795; Thu, 04 Aug 2016 11:34:24 -0700 (PDT) Received: from localhost ([2404:e800:e600:57b:dcfa:b5a4:c9d2:f744]) by smtp.gmail.com with ESMTPSA id k66sm17516121pfc.30.2016.08.04.11.34.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Aug 2016 11:34:24 -0700 (PDT) From: Jason Zaman To: selinux@tycho.nsa.gov Subject: [PATCH 02/12] seobject: use sorted() instead of .sort() Date: Fri, 5 Aug 2016 02:33:55 +0800 Message-Id: <1470335645-24224-3-git-send-email-jason@perfinion.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1470335645-24224-1-git-send-email-jason@perfinion.com> References: <1470335645-24224-1-git-send-email-jason@perfinion.com> X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Virus-Scanned: ClamAV using ClamSMTP 2to3 wanted to wrap all the .keys() calls in list() but doing sorted() directly is better. Signed-off-by: Jason Zaman --- policycoreutils/semanage/seobject.py | 68 ++++++++++++------------------------ 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/policycoreutils/semanage/seobject.py b/policycoreutils/semanage/seobject.py index 863d4a5..66ff00e 100644 --- a/policycoreutils/semanage/seobject.py +++ b/policycoreutils/semanage/seobject.py @@ -716,21 +716,17 @@ class loginRecords(semanageRecords): def customized(self): l = [] ddict = self.get_all(True) - keys = ddict.keys() - keys.sort() - for k in keys: + for k in sorted(ddict.keys()): l.append("-a -s %s -r '%s' %s" % (ddict[k][0], ddict[k][1], k)) return l def list(self, heading=1, locallist=0): ddict = self.get_all(locallist) ldict = self.get_all_logins() - lkeys = ldict.keys() - keys = ddict.keys() + lkeys = sorted(ldict.keys()) + keys = sorted(ddict.keys()) if len(keys) == 0 and len(lkeys) == 0: return - keys.sort() - lkeys.sort() if is_mls_enabled == 1: if heading: @@ -988,18 +984,15 @@ class seluserRecords(semanageRecords): def customized(self): l = [] ddict = self.get_all(True) - keys = ddict.keys() - keys.sort() - for k in keys: + for k in sorted(ddict.keys()): l.append("-a -L %s -r %s -R '%s' %s" % (ddict[k][1], ddict[k][2], ddict[k][3], k)) return l def list(self, heading=1, locallist=0): ddict = self.get_all(locallist) - keys = ddict.keys() - if len(keys) == 0: + if len(ddict) == 0: return - keys.sort() + keys = sorted(ddict.keys()) if is_mls_enabled == 1: if heading: @@ -1251,9 +1244,7 @@ class portRecords(semanageRecords): def customized(self): l = [] ddict = self.get_all(True) - keys = ddict.keys() - keys.sort() - for k in keys: + for k in sorted(ddict.keys()): if k[0] == k[1]: l.append("-a -t %s -p %s %s" % (ddict[k][0], k[2], k[0])) else: @@ -1262,10 +1253,9 @@ class portRecords(semanageRecords): def list(self, heading=1, locallist=0): ddict = self.get_all_by_type(locallist) - keys = ddict.keys() - if len(keys) == 0: + if len(ddict) == 0: return - keys.sort() + keys = sorted(ddict.keys()) if heading: print("%-30s %-8s %s\n" % (_("SELinux Port Type"), _("Proto"), _("Port Number"))) @@ -1488,18 +1478,15 @@ class nodeRecords(semanageRecords): def customized(self): l = [] ddict = self.get_all(True) - keys = ddict.keys() - keys.sort() - for k in keys: + for k in sorted(ddict.keys()): l.append("-a -M %s -p %s -t %s %s" % (k[1], k[2], ddict[k][2], k[0])) return l def list(self, heading=1, locallist=0): ddict = self.get_all(locallist) - keys = ddict.keys() - if len(keys) == 0: + if len(ddict) == 0: return - keys.sort() + keys = sorted(ddict.keys()) if heading: print("%-18s %-18s %-5s %-5s\n" % ("IP Address", "Netmask", "Protocol", "Context")) @@ -1679,18 +1666,15 @@ class interfaceRecords(semanageRecords): def customized(self): l = [] ddict = self.get_all(True) - keys = ddict.keys() - keys.sort() - for k in keys: + for k in sorted(ddict.keys()): l.append("-a -t %s %s" % (ddict[k][2], k)) return l def list(self, heading=1, locallist=0): ddict = self.get_all(locallist) - keys = ddict.keys() - if len(keys) == 0: + if len(ddict) == 0: return - keys.sort() + keys = sorted(ddict.keys()) if heading: print("%-30s %s\n" % (_("SELinux Interface"), _("Context"))) @@ -2031,9 +2015,7 @@ class fcontextRecords(semanageRecords): def customized(self): l = [] fcon_dict = self.get_all(True) - keys = fcon_dict.keys() - keys.sort() - for k in keys: + for k in sorted(fcon_dict.keys()): if fcon_dict[k]: l.append("-a -f %s -t %s '%s'" % (file_type_str_to_option[k[1]], fcon_dict[k][2], k[0])) @@ -2044,12 +2026,10 @@ class fcontextRecords(semanageRecords): def list(self, heading=1, locallist=0): fcon_dict = self.get_all(locallist) - keys = fcon_dict.keys() - if len(keys) != 0: - keys.sort() + if len(fcon_dict) != 0: if heading: print("%-50s %-18s %s\n" % (_("SELinux fcontext"), _("type"), _("Context"))) - for k in keys: + for k in sorted(fcon_dict.keys()): if fcon_dict[k]: if is_mls_enabled: print("%-50s %-18s %s:%s:%s:%s " % (k[0], k[1], fcon_dict[k][0], fcon_dict[k][1], fcon_dict[k][2], translate(fcon_dict[k][3], False))) @@ -2223,9 +2203,7 @@ class booleanRecords(semanageRecords): def customized(self): l = [] ddict = self.get_all(True) - keys = ddict.keys() - keys.sort() - for k in keys: + for k in sorted(ddict.keys()): if ddict[k]: l.append("-m -%s %s" % (ddict[k][2], k)) return l @@ -2234,18 +2212,16 @@ class booleanRecords(semanageRecords): on_off = (_("off"), _("on")) if use_file: ddict = self.get_all(locallist) - keys = ddict.keys() - for k in keys: + for k in sorted(ddict.keys()): if ddict[k]: print("%s=%s" % (k, ddict[k][2])) return ddict = self.get_all(locallist) - keys = ddict.keys() - if len(keys) == 0: + if len(ddict) == 0: return if heading: print("%-30s %s %s %s\n" % (_("SELinux boolean"), _("State"), _("Default"), _("Description"))) - for k in keys: + for k in sorted(ddict.keys()): if ddict[k]: print("%-30s (%-5s,%5s) %s" % (k, on_off[selinux.security_get_boolean_active(k)], on_off[ddict[k][2]], self.get_desc(k)))