From nobody Sat Jul 5 15:54:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1521296688074504.1252340750301; Sat, 17 Mar 2018 07:24:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B9FC02BBE08; Sat, 17 Mar 2018 14:24:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8B32C80F66; Sat, 17 Mar 2018 14:24:46 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 52DCA180BAD7; Sat, 17 Mar 2018 14:24:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2HENuDJ000537 for ; Sat, 17 Mar 2018 10:23:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id C7DF75D70A; Sat, 17 Mar 2018 14:23:56 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C20FD5D6A5 for ; Sat, 17 Mar 2018 14:23:56 +0000 (UTC) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B400719CB85 for ; Sat, 17 Mar 2018 14:23:55 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id 5so7955101wmh.0 for ; Sat, 17 Mar 2018 07:23:55 -0700 (PDT) Received: from rst.Home ([2a02:c7d:692a:c500:1ebc:73f3:5f60:b131]) by smtp.gmail.com with ESMTPSA id i66sm11060550wmd.0.2018.03.17.07.23.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 17 Mar 2018 07:23:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rbJBpWPHdDPH4jUyNwSK8IpHIjrJgjYVUkvtvWoPiXo=; b=MPwjQ22gcBv2JhOBd/VbqgHtuI+tXruGsXZnbg9r7Fh0fIh5XRgqPFpGyQIVRnAKCj /lmlZ/XqqXoCb5D/cLBx+O35jPaLvGOxT+WCtpMO0MbCihnsx6w6W7v3eUR/u1auyZKF puBfoysctnS/+qsoTWwxqbEVcvR6hNLvRFQyhFhxGtFvomfXYQy9SmaVSMwsLmTviYb7 rfREYLZ/fBouJv13ZXjFZrEpVnpvDdoTruYmpZalu9tUyMHMsSm7oOxGZwVBSaU0XjvI gBi/yrwaNCCgaT6+VxzbHp1sW4QeAsk3hIfxM+tGplWuHKJTwOr15LHxuipJNHywyOC3 IErw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rbJBpWPHdDPH4jUyNwSK8IpHIjrJgjYVUkvtvWoPiXo=; b=csz2mdeeeThRQ2f7/4RtZZJMkNvWd/YNDRbGNWCDElCPRV6rjP+B84HKxkRODOH1IO qnT6HtPMDZMKCIcad9qwE3M2YCisnHCGOYXhOt0dhi+5pSuwn0urZRxGpDlUqn8+h/ZQ HFldwPiqaKnAWSFmBTDQJlki5+nmdnOvhn6DnxzspvjujsSWvOA8dZFe0+TqkU+xkN63 vKaJUlMyp8uQd5icodURmYTn1dlJsPXHukk71PX1rKnYITM5OmoJ1fu+NPa0W9PZeAQR C/eRSOIj0Z+xlKPgwbkWp/RVC0zblaYytBa2SXVboxjWGTcLN75BB82K0PDxQPbeMYbi lbzQ== X-Gm-Message-State: AElRT7H8nyvYG7u0oLELJQuQKmJI+z6EGKaHRdKZQYJJIppScPJO7/GN 72S/akCm5Hwe/wXWGYXazQOWlZmT X-Google-Smtp-Source: AG47ELsGknV++oNQBkgLxqkWxeKzPU9qBaftew1nOq+efLd+VaLBI3HCmQQd/rpmqtJdaHDmlyPlCw== X-Received: by 10.28.116.14 with SMTP id p14mr4677927wmc.117.1521296634120; Sat, 17 Mar 2018 07:23:54 -0700 (PDT) From: Radostin Stoyanov To: libvir-list@redhat.com Date: Sat, 17 Mar 2018 14:23:25 +0000 Message-Id: <20180317142340.11653-8-rstoyanov1@gmail.com> In-Reply-To: <20180317142340.11653-1-rstoyanov1@gmail.com> References: <20180317142340.11653-1-rstoyanov1@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 17 Mar 2018 14:23:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 17 Mar 2018 14:23:55 +0000 (UTC) for IP:'74.125.82.68' DOMAIN:'mail-wm0-f68.google.com' HELO:'mail-wm0-f68.google.com' FROM:'rstoyanov1@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.12 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 74.125.82.68 mail-wm0-f68.google.com 74.125.82.68 mail-wm0-f68.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Radostin Stoyanov Subject: [libvirt] [PATCH 07/22] esx_vi_generator: Simplify get_occurrence_comment X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 17 Mar 2018 14:24:47 +0000 (UTC) X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Reduce the number of if-statements and use a single return. Utilise a dictionary to map between occurrences and values. Signed-off-by: Radostin Stoyanov Reviewed-by: Daniel P. Berrang=C3=A9 --- src/esx/esx_vi_generator.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py index 1641a2a1e..e4890c61b 100755 --- a/src/esx/esx_vi_generator.py +++ b/src/esx/esx_vi_generator.py @@ -75,16 +75,16 @@ class Member: =20 =20 def get_occurrence_comment(self): - if self.occurrence =3D=3D OCCURRENCE__REQUIRED_ITEM: - return "/* required */" - elif self.occurrence =3D=3D OCCURRENCE__REQUIRED_LIST: - return "/* required, list */" - elif self.occurrence =3D=3D OCCURRENCE__OPTIONAL_ITEM: - return "/* optional */" - elif self.occurrence =3D=3D OCCURRENCE__OPTIONAL_LIST: - return "/* optional, list */" - - raise ValueError("unknown occurrence value '%s'" % self.occurrence) + occurrence_map =3D { + OCCURRENCE__REQUIRED_ITEM: "/* required */", + OCCURRENCE__REQUIRED_LIST: "/* required, list */", + OCCURRENCE__OPTIONAL_ITEM: "/* optional */", + OCCURRENCE__OPTIONAL_LIST: "/* optional, list */" + } + if self.occurrence not in occurrence_map: + raise ValueError("unknown occurrence value '%s'" % self.occurr= ence) + + return occurrence_map[self.occurrence] =20 =20 =20 --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list