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

Skip to content

Commit 8689112

Browse files
committed
Revert "fixed function names, as well as added a better check for the caller of get_image_download_script"
This reverts commit 0582283.
1 parent 0582283 commit 8689112

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

plotly/offline/offline.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import warnings
1212
from pkg_resources import resource_string
1313
import time
14-
import sys
1514
import webbrowser
1615

1716
import plotly
@@ -50,13 +49,17 @@ def get_plotlyjs():
5049
plotlyjs = resource_string('plotly', path).decode('utf-8')
5150
return plotlyjs
5251

53-
def get_image_download_script():
52+
def get_image_download_script(caller):
5453
'''
55-
This function will return a script that will download an image of the
56-
most recently rendered Plotly plot
54+
This function will return a script that will download an image of a Plotly
55+
plot.
56+
57+
Keyword Arguments:
58+
caller ('plot', 'iplot') -- specifies which function made the call for the
59+
download script. If `iplot`, then an extra condition is added into the
60+
download script to ensure that download prompts aren't iniitated on
61+
page reloads.
5762
'''
58-
# get the name of the function that called `get_image_download_script`
59-
caller = sys._getframe(1).f_code.co_name
6063

6164
if caller == 'iplot':
6265
check_start = 'if(document.readyState == \'complete\') {{'
@@ -300,11 +303,11 @@ def iplot(figure_or_data, show_link=True, link_text='Export to plot.ly',
300303
)
301304
)
302305
# if image is given, and is a valid format, we will download the image
303-
script = get_image_download_script().format(format=image,
304-
width=image_width,
305-
height=image_height,
306-
filename=filename,
307-
plot_id=plotdivid)
306+
script = image_download_script('iplot').format(format=image,
307+
width=image_width,
308+
height=image_height,
309+
filename=filename,
310+
plot_id=plotdivid)
308311
# allow time for the plot to draw
309312
time.sleep(1)
310313
# inject code to download an image of the plot
@@ -423,7 +426,7 @@ def plot(figure_or_data,
423426
)
424427
# if the check passes then download script is injected.
425428
# write the download script:
426-
script = get_image_download_script()
429+
script = image_download_script('plot')
427430
script = script.format(format=image,
428431
width=image_width,
429432
height=image_height,

0 commit comments

Comments
 (0)