From: Christian Herdtweck Date: Tue, 3 Mar 2026 09:55:53 +0000 (+0100) Subject: Fix warnings in dial.py X-Git-Tag: v1.7.5~4 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=9766b37ee0dd125c13b49a8bed248b4fbd9d0207;p=pyi2ncommon Fix warnings in dial.py Building dist showed a syntax warning in dial.py due to missing "r" prefix. Remove out-dated treatment of missing ipaddress module (available since py3.3) --- diff --git a/src/dial.py b/src/dial.py index 35144f2..f9aad32 100644 --- a/src/dial.py +++ b/src/dial.py @@ -48,19 +48,13 @@ completion timeout is currently 10 seconds (see the definition of import re import io -import time import logging +import ipaddress log = logging.getLogger('pyi2ncommon.dial') from . import cnfvar from . import sysmisc -HAVE_IPADDRESS = True -try: - import ipaddress -except ImportError: # guest - HAVE_IPADDRESS = False - __all__ = ( "arnied_dial_hangup", "arnied_dial_doc", "arnied_dial_permanent", "dialout", "get_wan_address", "DIALOUT_MODE_PERMANENT", "DIALOUT_MODE_MANUAL", "DIALOUT_MODE_DEFAULT", "DIALOUT_MODE_BY_NAME" ) @@ -73,7 +67,7 @@ DIALOUT_MODE_CNF = {DIALOUT_MODE_PERMANENT: "ONLINE", DIALOUT_MODE_MANUAL: "MANU # compiling this regex needs the provider id and is postponed due to # the peculiar implementation of the connd online condition -NEEDLE_MEMO = " \[%s\] :(.*connected online fsm.*)" +NEEDLE_MEMO = r" \[%s\] :(.*connected online fsm.*)" NEEDLE_OFFLINE = re.compile("connection map:\nend of connection map") DIALTOOLS_HANGUP_BIN = "/usr/intranator/bin/hangup" @@ -109,7 +103,7 @@ def arnied_dial_hangup(block=False): """ log.debug("requested arnied_dial_hangup%s", " (blocking)" if block else "") - if block is False: + if not block: succ, _, _ = sysmisc.run_cmd_with_pipe([DIALTOOLS_HANGUP_BIN]) return sysmisc.RUN_RESULT_OK if succ is True else sysmisc.RUN_RESULT_FAIL @@ -132,7 +126,7 @@ def arnied_dial_doc(prid="P1", block=False): :rtype: int (dial result as above) """ log.debug("requested arnied_dial_doc%s", " (blocking)" if block else "") - if block is False: + if not block: succ, _, _ = sysmisc.run_cmd_with_pipe([DIALTOOLS_DOC_BIN, prid]) return sysmisc.RUN_RESULT_OK if succ is True else sysmisc.RUN_RESULT_FAIL res, err = sysmisc.cmd_block_till([DIALTOOLS_DOC_BIN, prid], @@ -169,7 +163,7 @@ def arnied_dial_permanent(prid="P1", block=False): store.commit(cnf) return True, "", None - if block is False: + if not block: succ, out, _ = aux() return sysmisc.RUN_RESULT_OK if succ is True else sysmisc.RUN_RESULT_FAIL @@ -196,12 +190,12 @@ def dialout(mode=DIALOUT_MODE_DEFAULT, prid="P1", block=True): log.info("go online with provider") dmode = None - if isinstance(mode, int) is True: + if isinstance(mode, int): dmode = mode - elif isinstance(mode, str) is True: + elif isinstance(mode, str): try: dmode = DIALOUT_MODE_BY_NAME[mode] - except Exception: + except KeyError: log.error("invalid online mode name “%s” requested" % mode) pass @@ -227,9 +221,8 @@ def get_wan_address(vm=None): :type vm: virttest.qemu_vm.VM | None :returns: The IPv4 address. For correctness, it will use the - ipaddress module if available. Otherwise it falls back - on untyped data. - :rtype: None | (ipaddress.IPv4Address | str) + ipaddress module + :rtype: None | ipaddress.IPv4Address """ log.info("query current lease") if vm is None: @@ -246,8 +239,5 @@ def get_wan_address(vm=None): break if l.find("connected online fsm IP:") != -1: addr = l[l.find("IP:")+3:l.find(" )\n")] # beurk - if HAVE_IPADDRESS is True: - return ipaddress.IPv4Address(str(addr)) - else: - return addr + return ipaddress.IPv4Address(str(addr)) return None