1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
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}]'
|