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

Skip to content

Commit ba01726

Browse files
committed
Merge pull request plotly#24 from plotly/variable_server_endpoint
Variable server endpoint
2 parents f5e9e68 + 09a9a8c commit ba01726

File tree

5 files changed

+186
-142
lines changed

5 files changed

+186
-142
lines changed

circle.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies:
1212
- pip install matplotlib
1313
- pip install -I .
1414
- cd ~ && python -c "import plotly"
15+
- chmod 000 ~/.plotly && python -c "import plotly"
1516

1617
## Customize database setup (pass)
1718

plotly/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from . version import __version__
22
import graph_objs
33
import plotly
4-
import tools
4+
import tools
5+
import utils

plotly/plotly/plotly.py

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import copy
2323
import base64
2424
import os
25-
from .. import utils
25+
from .. import utils # TODO make non-relative
2626
from .. import tools
2727
from .. import exceptions
2828
from .. import version
@@ -42,33 +42,20 @@
4242

4343
_plot_options = dict()
4444

45-
_plotly_url = "https://plot.ly" # do not append final '/' here for url!
45+
### test file permissions and make sure nothing is corrupted ###
46+
tools.ensure_local_plotly_files()
4647

4748
### _credentials stuff ###
4849

50+
4951
def sign_in(username, api_key):
5052
"""Set module-scoped _credentials for session. Verify with plotly."""
5153
global _credentials
5254
_credentials['username'], _credentials['api_key'] = username, api_key
5355
# TODO: verify these _credentials with plotly
5456

5557

56-
### _plot_options stuff ###
57-
58-
# def load_plot_options():
59-
# """ Import the plot_options from file into the module-level _plot_options.
60-
# """
61-
# global _plot_options
62-
# _plot_options = _plot_options.update(tools.get_plot_options_file())
63-
#
64-
#
65-
# def save_plot_options(**kwargs):
66-
# """ Save the module-level _plot_options to file for later access
67-
# """
68-
# global _plot_options
69-
# update_plot_options(**kwargs)
70-
# tools.save_plot_options_file(**_plot_options)
71-
58+
### plot options stuff ###
7259

7360
def update_plot_options(**kwargs):
7461
""" Update the module-level _plot_options
@@ -273,7 +260,8 @@ def get_figure(file_owner, file_id, raw=False):
273260
`graph objects`.
274261
275262
"""
276-
server = _plotly_url
263+
264+
plotly_rest_url = tools.get_config_file()['plotly_domain']
277265
resource = "/apigetfile/{username}/{file_id}".format(username=file_owner,
278266
file_id=file_id)
279267
(username, api_key) = _validation_key_logic()
@@ -298,7 +286,7 @@ def get_figure(file_owner, file_id, raw=False):
298286
"The 'file_id' argument must be a non-negative number."
299287
)
300288

301-
response = requests.get(server + resource, headers=headers)
289+
response = requests.get(plotly_rest_url + resource, headers=headers)
302290
if response.status_code == 200:
303291
content = json.loads(response.content)
304292
response_payload = content['payload']
@@ -317,11 +305,12 @@ def get_figure(file_owner, file_id, raw=False):
317305
"There was an error retrieving this file")
318306

319307

308+
@utils.template_doc(**tools.get_config_file())
320309
class Stream:
321310
""" Interface to Plotly's real-time graphing API.
322311
323312
Initialize a Stream object with a stream_id
324-
found in https://plot.ly/settings.
313+
found in {plotly_domain}/settings.
325314
Real-time graphs are initialized with a call to `plot` that embeds
326315
your unique `stream_id`s in each of the graph's traces. The `Stream`
327316
interface plots data to these traces, as identified with the unique
@@ -334,7 +323,7 @@ class Stream:
334323
Stream example:
335324
# Initialize a streaming graph
336325
# by embedding stream_id's in the graph's traces
337-
>>> stream_id = "your_stream_id" # See https://plot.ly/settings
326+
>>> stream_id = "your_stream_id" # See {plotly_domain}/settings
338327
>>> py.plot(Data([Scatter(x=[],
339328
y=[],
340329
stream=dict(token=stream_id, maxpoints=100))])
@@ -344,9 +333,10 @@ class Stream:
344333
>>> stream.write(dict(x=1, y=1)) # Plot (1, 1) in your graph
345334
"""
346335

336+
@utils.template_doc(**tools.get_config_file())
347337
def __init__(self, stream_id):
348338
""" Initialize a Stream object with your unique stream_id.
349-
Find your stream_id at https://plot.ly/settings.
339+
Find your stream_id at {plotly_domain}/settings.
350340
351341
For more help, see: `help(plotly.plotly.Stream)`
352342
or see examples and tutorials here:
@@ -362,12 +352,13 @@ def open(self):
362352
or see examples and tutorials here:
363353
http://nbviewer.ipython.org/github/plotly/python-user-guide/blob/master/s7_streaming/s7_streaming.ipynb
364354
"""
365-
self._stream = chunked_requests.Stream('stream.plot.ly',
355+
356+
streaming_url = tools.get_config_file()['plotly_streaming_domain']
357+
self._stream = chunked_requests.Stream(streaming_url,
366358
80,
367-
{'Host': 'stream.plot.ly',
359+
{'Host': streaming_url,
368360
'plotly-streamtoken': self.stream_id})
369361

370-
371362
def write(self, data, layout=None, validate=True,
372363
reconnect_on=(200, '', 408)):
373364
""" Write `data` to your stream. This will plot the
@@ -470,8 +461,8 @@ def get(figure):
470461
'plotly-version': '2.0',
471462
'plotly-platform': 'python'}
472463

473-
server = "https://plot.ly/apigenimage/"
474-
res = requests.post(server,
464+
url = tools.get_config_file()['plotly_domain'] + "/apigenimage/"
465+
res = requests.post(url,
475466
data=json.dumps(figure,
476467
cls=utils._plotlyJSONEncoder),
477468
headers=headers)
@@ -543,9 +534,7 @@ def _send_to_plotly(figure, **plot_options):
543534
origin='plot',
544535
kwargs=kwargs)
545536

546-
# TODO: this doesn't work yet for ppl's individual servers for testing...
547-
# url = _plotly_url + "/clientresp"
548-
url = "https://plot.ly/clientresp"
537+
url = tools.get_config_file()['plotly_domain'] + "/clientresp"
549538

550539
r = requests.post(url, data=payload)
551540
r.raise_for_status()
@@ -577,4 +566,3 @@ def _validation_key_logic():
577566
if username is None or api_key is None:
578567
raise exceptions.PlotlyLocalCredentialsError()
579568
return (username, api_key)
580-

0 commit comments

Comments
 (0)