Keep original IP address if the IP address is not in address map

dict.get() returns None if the key is not in dict.
This commit is contained in:
YOKOTA Hiroshi 2022-10-22 22:04:42 +09:00
parent 70ba016b1f
commit b5cdb0e6ea
2 changed files with 10 additions and 2 deletions

View File

@ -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}]'

View File

@ -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}]'