[Git][NTPsec/ntpsec][master] Remove useless parentheses in python code

Matt Selsky gitlab at mg.gitlab.com
Sun Aug 5 18:36:32 UTC 2018


Matt Selsky pushed to branch master at NTPsec / ntpsec


Commits:
daa3ecac by Matt Selsky at 2018-08-05T18:32:56Z
Remove useless parentheses in python code

as reported by Sonarqube's SonarCloud platform

I also updated the indentation to better comply with PEP8's E125/E129
- E125 continuation line with same indent as next logical line
- E129 visually indented line with same indent as next logical line

- - - - -


5 changed files:

- ntpclients/ntpmon.py
- ntpclients/ntpq.py
- pylib/packet.py
- tests/pylib/test_agentx_packet.py
- wafhelpers/check_pthread.py


Changes:

=====================================
ntpclients/ntpmon.py
=====================================
@@ -333,8 +333,8 @@ if __name__ == '__main__':
                                                        peer.associd)
                             data = data.encode('UTF-8')
                             stdscr.addstr(data, hilite)
-                            if (('refid' in variables and
-                                 'INIT' in variables['refid'])):
+                            if ('refid' in variables and
+                                    'INIT' in variables['refid']):
                                 initphase = True
 
                         # Now the MRU report


=====================================
ntpclients/ntpq.py
=====================================
@@ -276,9 +276,9 @@ usage: help [ command ]
             "===========================================================\n")
         for (i, peer) in enumerate(self.peers):
             statval = ntp.control.CTL_PEER_STATVAL(peer.status)
-            if ((not showall and
-                 (statval & (ntp.control.CTL_PST_CONFIG |
-                             ntp.control.CTL_PST_REACH)) == 0)):
+            if (not showall and
+                    (statval & (ntp.control.CTL_PST_CONFIG |
+                                ntp.control.CTL_PST_REACH)) == 0):
                 continue
             sw = ntp.util.PeerStatusWord(peer.status)
             display = "%3d %5u  %04x   %3.3s  %4s  %4.4s %9.9s %11s %2lu" \
@@ -309,10 +309,10 @@ usage: help [ command ]
                 self.say("=" * (maxhostlen + 1))
             self.say(("=" * report.width()) + "\n")
             for peer in self.peers:
-                if ((not showall and
-                     not (ntp.control.CTL_PEER_STATVAL(peer.status) &
-                          (ntp.control.CTL_PST_CONFIG |
-                           ntp.control.CTL_PST_REACH)))):
+                if (not showall and
+                    not (ntp.control.CTL_PEER_STATVAL(peer.status) &
+                         (ntp.control.CTL_PST_CONFIG |
+                          ntp.control.CTL_PST_REACH))):
                     if self.debug:
                         self.warn("eliding [%d]\n" % peer.associd)
                     continue
@@ -370,8 +370,8 @@ usage: help [ command ]
             except:
                 self.warn("Invalid associd literal.\n")
                 return -1
-            if ((associd != 0 and
-                 associd not in [peer.associd for peer in self.peers])):
+            if (associd != 0 and
+                    associd not in [peer.associd for peer in self.peers]):
                 self.warn("Unknown associd.\n")
                 return -1
             else:
@@ -587,8 +587,8 @@ usage: delay [ msec ]
                 session.ai_family = socket.AF_INET6
                 tokens.pop(0)
             try:
-                if ((tokens and
-                     self.session.openhost(tokens[0], session.ai_family))):
+                if (tokens and
+                        self.session.openhost(tokens[0], session.ai_family)):
                     print("current host set to %s" % self.session.hostname)
                 elif self.session.havehost():
                     print("current host remains %s" % self.session.hostname)
@@ -800,8 +800,8 @@ usage: authenticate [yes|no]
         else:
             try:
                 newversion = int(line)
-                if ((newversion >= ntp.magic.NTP_OLDVERSION and
-                     newversion <= ntp.magic.NTP_VERSION)):
+                if (newversion >= ntp.magic.NTP_OLDVERSION and
+                        newversion <= ntp.magic.NTP_VERSION):
                     self.pktversion = newversion
                 else:
                     print("versions %d to %d, please"
@@ -1728,11 +1728,11 @@ if __name__ == '__main__':
     if len(arguments) == 0:
         interpreter.chosts.append((DEFHOST, session.ai_family))
 
-    if ((len(interpreter.ccmds) == 0 and
-            not interpreter.interactive and
-            os.isatty(0) and
-            os.isatty(1)
-         )):
+    if (len(interpreter.ccmds) == 0 and
+                not interpreter.interactive and
+                os.isatty(0) and
+                os.isatty(1)
+            ):
         interpreter.interactive = True
 
     try:


=====================================
pylib/packet.py
=====================================
@@ -1594,8 +1594,8 @@ This combats source address spoofing
                 for i in range(len(span.entries)):
                     e = span.entries[len(span.entries) - i - 1]
                     incr = ", addr.%d=%s, last.%d=%s" % (i, e.addr, i, e.last)
-                    if ((len(req_buf) + len(incr) >=
-                            ntp.control.CTL_MAX_DATA_LEN)):
+                    if (len(req_buf) + len(incr) >=
+                            ntp.control.CTL_MAX_DATA_LEN):
                         break
                     else:
                         req_buf += incr


=====================================
tests/pylib/test_agentx_packet.py
=====================================
@@ -705,8 +705,8 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(pkt_new.nonReps, 1)
         self.assertEqual(pkt_new.maxReps, 5)
         self.assertEqual(pkt_new.oidranges,
-                         ((srch((1, 2), (3, 4), False),
-                           srch((6, 7), (8, 9), True))))
+                         (srch((1, 2), (3, 4), False),
+                          srch((6, 7), (8, 9), True)))
         self.assertEqual(pkt_new.context, "blah")
         # Test decoding, little endian
         header, body = slicedata(pkt_LE_str, 20)
@@ -716,8 +716,8 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(pkt_LE_new.nonReps, 1)
         self.assertEqual(pkt_LE_new.maxReps, 5)
         self.assertEqual(pkt_LE_new.oidranges,
-                         ((srch((1, 2), (3, 4), False),
-                           srch((6, 7), (8, 9), True))))
+                         (srch((1, 2), (3, 4), False),
+                          srch((6, 7), (8, 9), True)))
         self.assertEqual(pkt_LE_new.context, "blah")
         # Test packetVars
         self.assertEqual(pkt_new.packetVars(),


=====================================
wafhelpers/check_pthread.py
=====================================
@@ -21,8 +21,8 @@ def check_pthread_header_lib(ctx):
     ctx.check_cc(lib="thr", mandatory=False,
                  comment="thr library, required by some operating systems.")
 
-    if ((ctx.get_define("HAVE_PTHREAD_H") and
-            (ctx.env.LIB_PTHREAD or ctx.env.LIB_THR))):
+    if (ctx.get_define("HAVE_PTHREAD_H") and
+            (ctx.env.LIB_PTHREAD or ctx.env.LIB_THR)):
         ctx.env.PTHREAD_HEADER_LIB = True
 
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/daa3ecac2442b21b64555257557296108167be58

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/daa3ecac2442b21b64555257557296108167be58
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20180805/fba8bed4/attachment-0001.html>


More information about the vc mailing list