From: YOKOTA Hiroshi <yokota.hgml@gmail.com>
Date: Sat, 22 Oct 2022 22:04:42 +0900
Subject: Keep original IP address if the IP address is not in address map

dict.get() returns None if the key is not in dict.
---
 src/calibre/gui2/actions/device.py     | 6 +++++-
 src/calibre/gui2/preferences/server.py | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/calibre/gui2/actions/device.py b/src/calibre/gui2/actions/device.py
index 0f22394..625ba49 100644
--- a/src/calibre/gui2/actions/device.py
+++ b/src/calibre/gui2/actions/device.py
@@ -27,7 +27,11 @@ def local_url_for_content_server():
     from calibre.srv.opts import server_config
     opts = server_config()
     interface = opts.listen_on or '0.0.0.0'
-    interface = {'0.0.0.0': '127.0.0.1', '::':'::1'}.get(interface)
+
+    addr_map = {'0.0.0.0': '127.0.0.1',
+                '::':      '::1'}
+    if interface in addr_map:
+        interface = addr_map[interface]
 
     if is_ipv6_addr(interface):
         interface = f'[{interface}]'
diff --git a/src/calibre/gui2/preferences/server.py b/src/calibre/gui2/preferences/server.py
index ef9f130..98a3b78 100644
--- a/src/calibre/gui2/preferences/server.py
+++ b/src/calibre/gui2/preferences/server.py
@@ -1310,7 +1310,11 @@ class ConfigWidget(ConfigWidgetBase):
         prefix = self.advanced_tab.get('url_prefix') or ''
         protocol = 'https' if self.advanced_tab.has_ssl else 'http'
         lo = self.advanced_tab.get('listen_on') or '0.0.0.0'
-        lo = {'0.0.0.0': '127.0.0.1', '::':'::1'}.get(lo)
+
+        addr_map = {'0.0.0.0': '127.0.0.1',
+                    '::':      '::1'}
+        if lo in addr_map:
+            lo = addr_map[lo]
 
         if is_ipv6_addr(lo):
             lo = f'[{lo}]'
