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

Skip to content

Commit 4c06cc5

Browse files
committed
adding webagg.address parameter to rcParams
1 parent 5a24121 commit 4c06cc5

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

lib/matplotlib/backends/backend_webagg.py

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

231231
@classmethod
232-
def initialize(cls, url_prefix='', port=None):
232+
def initialize(cls, url_prefix='', port=None, address=None):
233233
if cls.initialized:
234234
return
235235

@@ -253,10 +253,15 @@ def random_ports(port, n):
253253
yield port + random.randint(-2 * n, 2 * n)
254254

255255
success = None
256+
257+
if address is None:
258+
cls.address = rcParams['webagg.address']
259+
else:
260+
cls.address = address
256261
cls.port = rcParams['webagg.port']
257262
for port in random_ports(cls.port, rcParams['webagg.port_retries']):
258263
try:
259-
app.listen(port)
264+
app.listen(port, cls.address)
260265
except socket.error as e:
261266
if e.errno != errno.EADDRINUSE:
262267
raise

lib/matplotlib/rcsetup.py

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

888+
def validate_webagg_address(s):
889+
if s is not None:
890+
import socket
891+
try:
892+
socket.inet_aton(s)
893+
except socket.error as e:
894+
raise ValueError("'webagg.address' is not a valid IP address")
895+
return s
896+
888897
# A validator dedicated to the named line styles, based on the items in
889898
# ls_mapper, and a list of possible strings read from Line2D.set_linestyle
890899
_validate_named_linestyle = ValidateInStrings('linestyle',
@@ -943,6 +952,7 @@ def _validate_linestyle(ls):
943952
'backend.qt4': ['PyQt4', validate_qt4],
944953
'backend.qt5': ['PyQt5', validate_qt5],
945954
'webagg.port': [8988, validate_int],
955+
'webagg.address': ['127.0.0.1', validate_webagg_address],
946956
'webagg.open_in_browser': [True, validate_bool],
947957
'webagg.port_retries': [50, validate_int],
948958
'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)