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

Skip to content

adding webagg.address parameter to rcParams #9008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/matplotlib/backends/backend_webagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def __init__(self, url_prefix=''):
template_path=core.FigureManagerWebAgg.get_static_file_path())

@classmethod
def initialize(cls, url_prefix='', port=None):
def initialize(cls, url_prefix='', port=None, address=None):
if cls.initialized:
return

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

success = None

if address is None:
cls.address = rcParams['webagg.address']
else:
cls.address = address
cls.port = rcParams['webagg.port']
for port in random_ports(cls.port, rcParams['webagg.port_retries']):
try:
app.listen(port)
app.listen(port, cls.address)
except socket.error as e:
if e.errno != errno.EADDRINUSE:
raise
Expand Down
11 changes: 11 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,16 @@ def validate_animation_writer_path(p):
modules["matplotlib.animation"].writers.set_dirty()
return p

def validate_webagg_address(s):
if s is not None:
import socket
try:
socket.inet_aton(s)
except socket.error as e:
raise ValueError("'webagg.address' is not a valid IP address")
return s
raise ValueError("'webagg.address' is not a valid IP address")

# A validator dedicated to the named line styles, based on the items in
# ls_mapper, and a list of possible strings read from Line2D.set_linestyle
_validate_named_linestyle = ValidateInStrings('linestyle',
Expand Down Expand Up @@ -943,6 +953,7 @@ def _validate_linestyle(ls):
'backend.qt4': ['PyQt4', validate_qt4],
'backend.qt5': ['PyQt5', validate_qt5],
'webagg.port': [8988, validate_int],
'webagg.address': ['127.0.0.1', validate_webagg_address],
'webagg.open_in_browser': [True, validate_bool],
'webagg.port_retries': [50, validate_int],
'nbagg.transparent': [True, validate_bool],
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/style/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

# A list of rcParams that should not be applied from styles
STYLE_BLACKLIST = {
'interactive', 'backend', 'backend.qt4', 'webagg.port',
'interactive', 'backend', 'backend.qt4', 'webagg.port', 'webagg.address',
'webagg.port_retries', 'webagg.open_in_browser', 'backend_fallback',
'toolbar', 'timezone', 'datapath', 'figure.max_open_warning',
'savefig.directory', 'tk.window_focus', 'docstring.hardcopy'}
Expand Down
3 changes: 3 additions & 0 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ backend : $TEMPLATE_BACKEND
# The port to use for the web server in the WebAgg backend.
# webagg.port : 8888

# The address on which the WebAgg web server should be reachable
# webagg.address : 127.0.0.1

# If webagg.port is unavailable, a number of other random ports will
# be tried until one that is available is found.
# webagg.port_retries : 50
Expand Down