Skip to content

Commit 7c68c29

Browse files
committed
Merge branch 'master' into embed-width-height
2 parents 73d9b66 + 31d55dc commit 7c68c29

File tree

17 files changed

+86
-60
lines changed

17 files changed

+86
-60
lines changed

plotly/exceptions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
1717
"""
1818
import json
19+
import six
1920

2021
## Base Plotly Error ##
2122

@@ -36,7 +37,9 @@ def __init__(self, requests_exception):
3637
if 'json' in content_type:
3738
content = requests_exception.response.content
3839
if content != '':
39-
res_payload = json.loads(requests_exception.response.content)
40+
res_payload = json.loads(
41+
requests_exception.response.content.decode('utf8')
42+
)
4043
if 'detail' in res_payload:
4144
self.message = res_payload['detail']
4245
else:

plotly/graph_objs/graph_objs.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def to_string(self, level=0, indent=4, eol='\n',
215215
216216
Example:
217217
218-
print obj.to_string()
218+
print(obj.to_string())
219219
220220
Keyword arguments:
221221
level (default = 0) -- set number of indentations to start with
@@ -323,14 +323,14 @@ def __setitem__(self, key, value):
323323
return super(PlotlyDict, self).__setitem__(key, value)
324324

325325
def _assign_id_to_src(self, src_name, src_value):
326-
if isinstance(src_value, basestring):
326+
if isinstance(src_value, six.string_types):
327327
src_id = src_value
328328
else:
329329
try:
330330
src_id = src_value.id
331331
except:
332-
err = ("{} does not have an `id` property. "
333-
"{} needs to be assigned to either an "
332+
err = ("{0} does not have an `id` property. "
333+
"{1} needs to be assigned to either an "
334334
"object with an `id` (like a "
335335
"plotly.grid_objs.Column) or a string. "
336336
"The `id` is a unique identifier "
@@ -430,7 +430,7 @@ def strip_style(self):
430430
elif not hasattr(self[key], '__iter__'):
431431
del self[key]
432432
except KeyError: # TODO: Update the JSON
433-
# print "'type' not in {0} for {1}".format(obj_key, key)
433+
# print("'type' not in {0} for {1}".format(obj_key, key))
434434
pass
435435

436436
def get_data(self):
@@ -605,7 +605,7 @@ def to_string(self, level=0, indent=4, eol='\n',
605605
606606
Example:
607607
608-
print obj.to_string()
608+
print(obj.to_string())
609609
610610
Keyword arguments:
611611
level (default = 0) -- set number of indentations to start with
@@ -759,7 +759,7 @@ def to_string(self, level=0, indent=4, eol='\n',
759759
760760
Example:
761761
762-
print obj.to_string()
762+
print(obj.to_string())
763763
764764
Keyword arguments:
765765
level (default = 0) -- set number of indentations to start with
@@ -962,7 +962,7 @@ def to_string(self, level=0, indent=4, eol='\n',
962962
963963
Example:
964964
965-
print obj.to_string()
965+
print(obj.to_string())
966966
967967
Keyword arguments:
968968
level (default = 0) -- set number of indentations to start with

plotly/grid_objs/grid_objs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __str__(self):
3535
def __repr__(self):
3636
return 'Column("{}", {})'.format(self.data, self.name)
3737

38-
def to_json(self):
38+
def to_plotly_json(self):
3939
return {'name': self.name, 'data': self.data}
4040

4141

plotly/plotly/plotly.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ def _fill_in_response_column_ids(cls, request_columns,
701701
for req_col in request_columns:
702702
for resp_col in response_columns:
703703
if resp_col['name'] == req_col.name:
704-
req_col.id = '{}/{}'.format(grid_id, resp_col['uid'])
704+
req_col.id = '{0}/{1}'.format(grid_id, resp_col['uid'])
705705
response_columns.remove(resp_col)
706706

707707
@classmethod
@@ -751,7 +751,7 @@ def upload(cls, grid, filename,
751751
grid.id = grid_id
752752

753753
plotly_domain = get_config()['plotly_domain']
754-
grid_url = '{}/~{}'.format(plotly_domain, grid_id.replace(':', '/'))
754+
grid_url = '{0}/~{1}'.format(plotly_domain, grid_id.replace(':', '/'))
755755

756756
if meta is not None:
757757
meta_ops.upload(meta, grid=grid)
@@ -800,8 +800,8 @@ def append_rows(cls, rows, grid=None, grid_url=None):
800800
raise exceptions.InputError(
801801
"The number of entries in "
802802
"each row needs to equal the number of columns in "
803-
"the grid. Row {} has {} {} but your "
804-
"grid has {} {}. "
803+
"the grid. Row {0} has {1} {2} but your "
804+
"grid has {3} {4}. "
805805
.format(row_i, len(row),
806806
'entry' if len(row) == 1 else 'entries',
807807
n_columns,
@@ -896,7 +896,7 @@ def parse_grid_id_args(cls, grid, grid_url):
896896
if supplied_arg_name == 'grid_url':
897897
path = urlparse(grid_url).path
898898
file_owner, file_id = path.replace("/~", "").split('/')[0:2]
899-
return '{}:{}'.format(file_owner, file_id)
899+
return '{0}:{1}'.format(file_owner, file_id)
900900
else:
901901
return grid.id
902902

@@ -913,7 +913,7 @@ def response_handler(cls, response):
913913
'json' in response.headers['content-type'] and
914914
len(response.content) > 0):
915915

916-
response_dict = json.loads(response.content)
916+
response_dict = json.loads(response.content.decode('utf8'))
917917

918918
if 'warnings' in response_dict and len(response_dict['warnings']):
919919
warnings.warn('\n'.join(response_dict['warnings']))
@@ -922,16 +922,19 @@ def response_handler(cls, response):
922922

923923
@classmethod
924924
def api_url(cls, resource):
925-
return ('{}/v2/{}'.format(get_config()['plotly_api_domain'],
925+
return ('{0}/v2/{1}'.format(get_config()['plotly_api_domain'],
926926
resource))
927927

928928
@classmethod
929929
def headers(cls):
930930
un, api_key = _get_session_username_and_key()
931-
encoded_un_key_pair = base64.b64encode('{}:{}'.format(un, api_key))
931+
encoded_un_key_pair = base64.b64encode(
932+
six.b('{0}:{1}'.format(un, api_key))
933+
).decode('utf8')
934+
932935
return {
933936
'authorization': 'Basic ' + encoded_un_key_pair,
934-
'plotly-client-platform': 'python {}'.format(version.__version__)
937+
'plotly-client-platform': 'python {0}'.format(version.__version__)
935938
}
936939

937940

plotly/tests/test_core/test_file/test_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_create_folder():
3636
@with_setup(init)
3737
def test_create_nested_folders():
3838
first_folder = _random_filename()
39-
nested_folder = '{}/{}'.format(first_folder, _random_filename())
39+
nested_folder = '{0}/{1}'.format(first_folder, _random_filename())
4040
py.file_ops.mkdirs(nested_folder)
4141

4242

plotly/tests/test_core/test_get_requests/test_get_requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,6 @@ def test_valid_request():
144144
# response_payload = content['payload']
145145
# figure = response_payload['figure']
146146
# if figure['data'][0]['x'] != [u'1', u'2', u'3']:
147-
# print 'ERROR'
147+
# print('ERROR')
148148
# return res
149149

plotly/tests/test_core/test_graph_objs/nose_tools.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,30 @@
1010
def compare_dict(dict1, dict2, equivalent=True, msg='', tol=10e-8):
1111
for key in dict1:
1212
if key not in dict2:
13-
return False, "{} should be {}".format(list(dict1.keys()), list(dict2.keys()))
13+
return (False,
14+
"{0} should be {1}".format(
15+
list(dict1.keys()), list(dict2.keys())))
1416
for key in dict1:
1517
if isinstance(dict1[key], dict):
1618
equivalent, msg = compare_dict(dict1[key],
1719
dict2[key],
1820
tol=tol)
1921
elif isinstance(dict1[key], Num) and isinstance(dict2[key], Num):
2022
if not comp_nums(dict1[key], dict2[key], tol):
21-
return False, "['{}'] = {} should be {}".format(key,
22-
dict1[key],
23-
dict2[key])
23+
return False, "['{0}'] = {1} should be {2}".format(key,
24+
dict1[key],
25+
dict2[key])
2426
elif is_num_list(dict1[key]) and is_num_list(dict2[key]):
2527
if not comp_num_list(dict1[key], dict2[key], tol):
26-
return False, "['{}'] = {} should be {}".format(key,
27-
dict1[key],
28-
dict2[key])
28+
return False, "['{0}'] = {1} should be {2}".format(key,
29+
dict1[key],
30+
dict2[key])
2931
elif not (dict1[key] == dict2[key]):
30-
return False, "['{}'] = {} should be {}".format(key,
31-
dict1[key],
32-
dict2[key])
32+
return False, "['{0}'] = {1} should be {2}".format(key,
33+
dict1[key],
34+
dict2[key])
3335
if not equivalent:
34-
return False, "['{}']".format(key) + msg
36+
return False, "['{0}']".format(key) + msg
3537
return equivalent, msg
3638

3739

plotly/tests/test_core/test_graph_objs/test_plotly_dict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_trivial():
1818

1919
# @raises(PlotlyError) # TODO: decide if this SHOULD raise error...
2020
# def test_instantiation_error():
21-
# print PlotlyDict(anything='something')
21+
# print(PlotlyDict(anything='something'))
2222

2323

2424
def test_validate():

plotly/tests/test_core/test_graph_objs/test_plotly_trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_trivial():
1818

1919
# @raises(PlotlyError) # TODO: decide if this SHOULD raise error...
2020
# def test_instantiation_error():
21-
# print Trace(anything='something')
21+
# print(Trace(anything='something'))
2222

2323

2424
def test_validate():

plotly/tests/test_core/test_graph_objs/test_scatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_trivial():
1919

2020
# @raises(PlotlyError) # TODO: decide if this SHOULD raise error...
2121
# def test_instantiation_error():
22-
# print PlotlyDict(anything='something')
22+
# print(PlotlyDict(anything='something'))
2323

2424

2525
def test_validate():

0 commit comments

Comments
 (0)