changeset 8522:82fc69e6d9d7

refactor/bug: handle case where netrc returns None. pyrefly flagged this. Python 3.14 (and 2.7) says authenticators() returns None if there is no matching host. Also the original exceptions IOError and TypeError appear to not be valid in this context. Rewrite to scope FileNotFoundError if .netrc is missing to just the one method call. Handle rest of flow with if/else not exception jump.
author John Rouillard <rouilj@ieee.org>
date Thu, 19 Feb 2026 22:15:12 -0500
parents 24e867f846dd
children b6b0da04e768
files roundup/scripts/roundup_mailgw.py
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/roundup/scripts/roundup_mailgw.py	Thu Feb 19 21:48:55 2026 -0500
+++ b/roundup/scripts/roundup_mailgw.py	Thu Feb 19 22:15:12 2026 -0500
@@ -215,15 +215,20 @@
 
     # the source will be a network server, so obtain the credentials to
     # use in connecting to the server
+    authenticator = None
     try:
         # attempt to obtain credentials from a ~/.netrc file
+        # returns None if host not found
         authenticator = netrc.netrc().authenticators(specification)
+    except FileNotFoundError:
+        # FileNotFoundError if no ~/.netrc file
+        pass
+
+    if authenticator:
         username = authenticator[0]
         password = authenticator[2]
         server = specification
-        # IOError if no ~/.netrc file, TypeError if the hostname
-        # not found in the ~/.netrc file:
-    except (IOError, TypeError):
+    else:
         match = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)',
                          specification)
         if match:

Roundup Issue Tracker: http://roundup-tracker.org/