Skip to content

Commit c063f23

Browse files
committed
validation warning can be triggered on get_config and set_config
1 parent 6e4622c commit c063f23

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

plotly/tools.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ def set_config_file(plotly_domain=None,
222222
ensure_local_plotly_files() # make sure what's there is OK
223223
utils.validate_world_readable_and_sharing_settings({
224224
'sharing': sharing, 'world_readable': world_readable})
225-
settings = get_config_file()
225+
226+
settings = get_config_file(validate=False)
226227
if isinstance(plotly_domain, six.string_types):
227-
#validate_domains(plotly_domain)
228228
settings['plotly_domain'] = plotly_domain
229229
elif plotly_domain is not None:
230230
raise TypeError('plotly_domain should be a string')
@@ -233,7 +233,6 @@ def set_config_file(plotly_domain=None,
233233
elif plotly_streaming_domain is not None:
234234
raise TypeError('plotly_streaming_domain should be a string')
235235
if isinstance(plotly_api_domain, six.string_types):
236-
#validate_domains(plotly_api_domain)
237236
settings['plotly_api_domain'] = plotly_api_domain
238237
elif plotly_api_domain is not None:
239238
raise TypeError('plotly_api_domain should be a string')
@@ -250,6 +249,14 @@ def set_config_file(plotly_domain=None,
250249
elif auto_open is not None:
251250
raise TypeError('auto_open should be a boolean')
252251

252+
# validate plotly_domain and plotly_api_domain
253+
list_of_domains = []
254+
if plotly_domain is not None:
255+
list_of_domains.append(plotly_domain)
256+
if plotly_api_domain is not None:
257+
list_of_domains.append(plotly_api_domain)
258+
validate_domains(*list_of_domains)
259+
253260
if isinstance(world_readable, bool):
254261
settings['world_readable'] = world_readable
255262
settings.pop('sharing')
@@ -265,7 +272,7 @@ def set_config_file(plotly_domain=None,
265272
ensure_local_plotly_files() # make sure what we just put there is OK
266273

267274

268-
def get_config_file(*args):
275+
def get_config_file(*args, validate=True):
269276
"""Return specified args from `~/.plotly/.config`. as tuple.
270277
271278
Returns all if no arguments are specified.
@@ -285,7 +292,8 @@ def get_config_file(*args):
285292
if domain in returned_obj:
286293
list_of_domains.append(returned_obj[domain])
287294

288-
validate_domains(*list_of_domains)
295+
if validate:
296+
validate_domains(*list_of_domains)
289297

290298
return returned_obj
291299

@@ -325,7 +333,7 @@ def get_embed(file_owner_or_url, file_id=None, width="100%", height=525):
325333
326334
"""
327335
plotly_rest_url = (session.get_session_config().get('plotly_domain') or
328-
get_config_file()['plotly_domain'])
336+
get_config_file(validate=False)['plotly_domain'])
329337
if file_id is None: # assume we're using a url
330338
url = file_owner_or_url
331339
if url[:len(plotly_rest_url)] != plotly_rest_url:
@@ -422,7 +430,7 @@ def embed(file_owner_or_url, file_id=None, width="100%", height=525):
422430
if file_id:
423431
plotly_domain = (
424432
session.get_session_config().get('plotly_domain') or
425-
get_config_file()['plotly_domain']
433+
get_config_file(validate=False)['plotly_domain']
426434
)
427435
url = "{plotly_domain}/~{un}/{fid}".format(
428436
plotly_domain=plotly_domain,
@@ -448,7 +456,7 @@ def embed(file_owner_or_url, file_id=None, width="100%", height=525):
448456

449457

450458
### mpl-related tools ###
451-
@utils.template_doc(**get_config_file())
459+
@utils.template_doc(**get_config_file(validate=False))
452460
def mpl_to_plotly(fig, resize=False, strip_style=False, verbose=False):
453461
"""Convert a matplotlib figure to plotly dictionary and send.
454462

0 commit comments

Comments
 (0)