Skip to content

Commit 90f1d64

Browse files
authored
Merge pull request #65 from azad-13/master
add python3 support and fix Rados.mon_command call for ceph pacific
2 parents e447557 + 3f37337 commit 90f1d64

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

app/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,18 @@ class UserConfig(dict):
7575

7676
def _string_decode_hook(self, data):
7777
rv = {}
78-
for key, value in data.iteritems():
78+
for key, value in data.items():
79+
try:
7980
if isinstance(key, unicode):
8081
key = key.encode('utf-8')
8182
if isinstance(value, unicode):
8283
value = value.encode('utf-8')
83-
rv[key] = value
84+
# unicode does not exist if python3 is used
85+
# ignore and don't do encoding, it is not
86+
# needed in python3
87+
except NameError:
88+
pass
89+
rv[key] = value
8490
return rv
8591

8692
def __init__(self):

app/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ApiResource(MethodView):
1111
def as_blueprint(cls, name=None):
1212
name = name or cls.endpoint
1313
bp = Blueprint(name, cls.__module__, url_prefix=cls.url_prefix)
14-
for endpoint, options in cls.url_rules.iteritems():
14+
for endpoint, options in cls.url_rules.items():
1515
url_rule = options.get('rule', '')
1616
defaults = options.get('defaults', {})
1717
bp.add_url_rule(url_rule, defaults=defaults, view_func=cls.as_view(endpoint))

app/dashboard/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class CephClusterCommand(dict):
4444

4545
def __init__(self, cluster, **kwargs):
4646
dict.__init__(self)
47-
ret, buf, err = cluster.mon_command(json.dumps(kwargs), '', timeout=5)
47+
ret, buf, err = cluster.mon_command(json.dumps(kwargs), b'', timeout=5)
4848
if ret != 0:
4949
self['err'] = err
5050
else:

app/graphite/views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
from flask import jsonify
88
from flask import current_app
99

10-
from urllib2 import urlopen
10+
# import urlopen from urllib.request / Python3
11+
# and fallback to urlopen from urllib2 / Python2
12+
try:
13+
from urllib.request import urlopen
14+
except ImportError:
15+
from urllib2 import urlopen
1116

1217
from app.base import ApiResource
1318

0 commit comments

Comments
 (0)