Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 608b24f

Browse files
authored
Merge pull request #9008 from schmeichelinho/webagg_local_addr
adding webagg.address parameter to rcParams
2 parents b477cf6 + 5b8c4c1 commit 608b24f

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

lib/matplotlib/backends/backend_webagg.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def __init__(self, url_prefix=''):
217217
template_path=core.FigureManagerWebAgg.get_static_file_path())
218218

219219
@classmethod
220-
def initialize(cls, url_prefix='', port=None):
220+
def initialize(cls, url_prefix='', port=None, address=None):
221221
if cls.initialized:
222222
return
223223

@@ -241,10 +241,15 @@ def random_ports(port, n):
241241
yield port + random.randint(-2 * n, 2 * n)
242242

243243
success = None
244+
245+
if address is None:
246+
cls.address = rcParams['webagg.address']
247+
else:
248+
cls.address = address
244249
cls.port = rcParams['webagg.port']
245250
for port in random_ports(cls.port, rcParams['webagg.port_retries']):
246251
try:
247-
app.listen(port)
252+
app.listen(port, cls.address)
248253
except socket.error as e:
249254
if e.errno != errno.EADDRINUSE:
250255
raise

lib/matplotlib/rcsetup.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,16 @@ def validate_animation_writer_path(p):
886886
modules["matplotlib.animation"].writers.set_dirty()
887887
return p
888888

889+
def validate_webagg_address(s):
890+
if s is not None:
891+
import socket
892+
try:
893+
socket.inet_aton(s)
894+
except socket.error as e:
895+
raise ValueError("'webagg.address' is not a valid IP address")
896+
return s
897+
raise ValueError("'webagg.address' is not a valid IP address")
898+
889899
# A validator dedicated to the named line styles, based on the items in
890900
# ls_mapper, and a list of possible strings read from Line2D.set_linestyle
891901
_validate_named_linestyle = ValidateInStrings('linestyle',
@@ -944,6 +954,7 @@ def _validate_linestyle(ls):
944954
'backend.qt4': ['PyQt4', validate_qt4],
945955
'backend.qt5': ['PyQt5', validate_qt5],
946956
'webagg.port': [8988, validate_int],
957+
'webagg.address': ['127.0.0.1', validate_webagg_address],
947958
'webagg.open_in_browser': [True, validate_bool],
948959
'webagg.port_retries': [50, validate_int],
949960
'nbagg.transparent': [True, validate_bool],

lib/matplotlib/style/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
# A list of rcParams that should not be applied from styles
3939
STYLE_BLACKLIST = {
40-
'interactive', 'backend', 'backend.qt4', 'webagg.port',
40+
'interactive', 'backend', 'backend.qt4', 'webagg.port', 'webagg.address',
4141
'webagg.port_retries', 'webagg.open_in_browser', 'backend_fallback',
4242
'toolbar', 'timezone', 'datapath', 'figure.max_open_warning',
4343
'savefig.directory', 'tk.window_focus', 'docstring.hardcopy'}

matplotlibrc.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ backend : $TEMPLATE_BACKEND
5353
# The port to use for the web server in the WebAgg backend.
5454
# webagg.port : 8888
5555

56+
# The address on which the WebAgg web server should be reachable
57+
# webagg.address : 127.0.0.1
58+
5659
# If webagg.port is unavailable, a number of other random ports will
5760
# be tried until one that is available is found.
5861
# webagg.port_retries : 50

0 commit comments

Comments
 (0)